在 Xamarin Android 中使用 Refit 发送 PDF 文件 [英] Sending a PDF file using Refit in Xamarin Android

查看:51
本文介绍了在 Xamarin Android 中使用 Refit 发送 PDF 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 API 的新手.我想知道是否有使用转换为 Base64 的 API 密钥发送 PDF 文件的正确方法.终点信息在截图链接上.

I'm new in using API. I would like to know if there is a proper way of sending a PDF file using an API key that is converted to Base64. End point information is on the screenshot link.

推荐答案

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; }
}

然后是一个看起来像这样的界面:

Then an Interface looking something like:

[Post("/upload")]
Task UploadPdf([Body]PdfFile file, [Header("x-axa-api-key")] string apiKey);

那么你的上传代码看起来像这样

then your upload code would look something like this

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

var pdf = new PdfFile();
var file = new File();

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

pdf.File = file;

await pdfApi.UploadPdf(pdf, "myapikey");

这篇关于在 Xamarin Android 中使用 Refit 发送 PDF 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆