微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用调整功能将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 举报,一经查实,本站将立刻删除。