Upload file as octet-stream using RestSharp 1.7 - restsharp

I'm trying to upload a file as octet-stream with RestSharp 1.7 but can't get it to work.
I've tried the following approaches:
Using restRequest.AddFile("file", documentContent, MediaTypeNames.Application.Octet);
This doesn't generate an octet-stream even if I specify it.
Using restRequest.AddBody(documentContent, MediaTypeNames.Application.Octet);
This seems to generate an octet-stream but the content doesn't seem to be the correct byte content. This worked on v.1.6.
If anyone have a working version of uploading streaming file data for RestSharp v.1.7 it would be greatly appreciated.

This is a bug in RestSharp v.107 according to this
https://github.com/restsharp/RestSharp/issues/1761
and the correction here:
https://github.com/restsharp/RestSharp/commit/a7d2662ef95269fab1e6dac2ef2ad3003c5c1e85
The solution for now is to use the following:
restRequest.AddParameter(new BodyParameter("", byteArrayContent, MediaTypeNames.Application.Octet, DataFormat.Binary));

Related

Unable to POST Multipart Form in Robot Framework Using Request Library

I have the following request in postman:
I have been using request library since the beginning automation on API: https://marketsquare.github.io/robotframework-requests/doc/RequestsLibrary.html#POST%20On%20Session
I tried to automate based on the postman request above with several trial and errors:
It always return 400 although the headers value set already correct:
What did I miss in the steps above?
Thank you in advance!
You should pass file descriptor not dictionary and "POST On Session" accepts file as "data" argument not "files". Try this
${file_stream} = Get File For Streaming Upload ${file_path}
${response} = POST On Session ${alias} ${URI} data=${file_stream}
On the second line you should add the rest arguments.
P.S. Next time please don't post code as screenshot, it makes hard for someone to copy and run it.
this is a false-negative due to the framework used by developers.
The developer has updated their framework and it works fine now.
No issues on the Robot Framework Request Library
Thank you.

Swagger UI endpoint doesn't return UTF-8 encoded response using ABP.IO

I am using abp framework as in http://www.abp.io
Now, executing this endpoint /api/abp/application-configuration using Swagger UI returns a json results see snippet below
Not sure why the results isn't UTF-8 encoded, I am expecting Mâle but got M�le
your help is appreciated
Answer:
Open the json file ie fr.json
Change the encoding to UTF-8 , you can use VS or Notepad++
Save the file
reopen the file to ensure change is done

There is any difference in uploading IFormFile vs Base64 string in .netcore web api?

I'm using .net core web api to accept, upload and download the file content.
I've already tried IFormFile and simple base64 encoded file content
UploadFile(IFormFile file)
UploadFile([FromBody] string base64Filecontentstring)
I'm just wondering if there is any difference in using any of those? If there is, which one should you use and when?
For small files Base64 will work fine, it's easy to handle and avoids dependency on Http.IFormFile in Domain.
But sending large files as Base64 using JSON is not a good idea. It will take a lot of memory & time for converting back to the actual image for copying on the Server.
I suggest the excellent article: https://medium.com/#ma1f/file-streaming-performance-in-dotnet-4dee608dd953 which shows that base64 performance is 5x-20x worse.
It's up to you.

How to read UTF metadata returned by PDFsharp?

I am trying to read some metadata from a PDF file and I am using PDFsharp for this. Unfortunately it seems to return the creator as UTF.
var reader = PdfReader.Open("data.pdf");
var creator = reader.Info.Creator; // þÿ\0M\0i\0c\0r\0o\0s\0o\0f\0t\0®\0 \0W\0o\0r\0d\0 \02\00\01\03
When using iTextSharp it works fine, which shows it's not a problem of the file.
var reader = new PdfReader("data.pdf");
var creator = reader.Info["Creator"]; // Microsoft® Word 2013
How can I read the creator correctly with PDFsharp? Since it seems to be an encoding issue I have the impression it should be a relatively easy fix, but I can't find it.
I can replicate this behaviour with PDFsharp 1.32 from 2013.
I cannot replicate this behaviour with PDFsharp 1.50 from 2018. At some time in the past five years this issue has been fixed.
Use the latest version of PDFsharp and you can access the meta data as expected. Now that is a very easy fix. No bad idea to always try the latest version first when you encounter problems.

OutOfMemoryException with RestSharp downloading big files

I've got an OutOfMemoryException using RestSharp when I downloading a big sized files ( 1GB ). After reading some papers seems the cause of it could be that RestSharp is using internally the class HttpWebRequest. Here's some explanation http://support.microsoft.com/kb/908573 ( cause -> This issue occurs because the .NET Framework buffers the outgoing data by default when you use the HttpWebRequest class. )
My question is about if it's possible with RestSharp download this sort of files or I must looking for other options. I've tryed several combination with code, but I do not find the correct way for doing only with RestSharp API.