Sending a PDF file using Refit in Xamarin Android

前端 未结 1 873
名媛妹妹
名媛妹妹 2021-01-26 14:15

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 screensh

相关标签:
1条回答
  • 2021-01-26 15:13
    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");
    
    0 讨论(0)
提交回复
热议问题