使用调整功能将PDF文件发送到API端点

问题描述

我是API新手。我想将PDF文件发送到端点,并且PDF应该转换为Base64。 但是我对如何在MainActivity中实现它一无所知。

我根据请求正文JSON创建了2个类

public class PdfFile
{
    [JsonProperty("file")]
    public File File { get; set; }
}

public class File
{
    [JsonProperty("mime")]
    public string MimeType { get; set; }
    [JsonProperty("data")]
    public string Base64Data { get; set; }
}

这是我的界面

namespace AXAtest.Interface
{
    [Headers("Content-Type: application/json")]
    interface IPdfApi
    {
        [Post("/upload")]
        Task UploadPdf([Body] PdfFile file,[Header("x-axa-api-key")] string apiKey);
    }
}

这是我在MainActivity中的代码,我不确定如何实现它。

pdfApi = RestService.For<IPdfApi>("https://goodmorning-axa-dev.azure-api.net");

            ConnectViews();

            sendResumeButton.Click += async delegate
            {
                Android.Support.V7.App.AlertDialog dialog = new EDMTDialogBuilder()
                .SetContext(this)
                .SetMessage("Sending...")
                .Build();

                try
                {
                    if (!dialog.IsShowing)
                        dialog.Show();

                    PdfFile pdfFile = new PdfFile();
                    File file = new File();

                    file.MimeType = "application/pdf";
                    file.Base64Data = "base64-data=";


                    File result = await pdfApi.UploadPdf(3);

                    Toast.MakeText(this,"Registration Successful",ToastLength.Short).Show();

                    if (dialog.IsShowing)
                        dialog.dismiss();

                }
                catch (System.Exception ex)
                {
                    Toast.MakeText(this,ex.Message,ToastLength.Short).Show();

                    if (dialog.IsShowing)
                        dialog.dismiss();
                }
            };

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)