How to send file through POST request in Zenno ?

  • Автор темы Автор темы cherubin
  • Дата начала Дата начала

cherubin

Client
Регистрация
06.06.2016
Сообщения
92
Реакции
7
Баллы
8
Hello,


I would like to do the same API call than with CURL, in Zenno :
CURL Code:
Развернуть Свернуть Копировать
curl -X POST -F data=@search.csv -F https://api-uploadcsv.com/search/csv/

How can i do that with the POST action ?

Thanks
 
If i convert the CURL code in C# i have this :

C#:
Развернуть Свернуть Копировать
// In production code, don't destroy the HttpClient through using, but better use IHttpClientFactory factory or at least reuse an existing HttpClient instance

// https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests

// https://www.aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/

using (var httpClient = new HttpClient())

{

    using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api-uploadcsv.com/search/csv/"))

    {

        var multipartContent = new MultipartFormDataContent();

        multipartContent.Add(new ByteArrayContent(File.ReadAllBytes("search.csv")), "data", Path.GetFileName("search.csv"));

        multipartContent.Add(new StringContent("adresse"), "columns");

        multipartContent.Add(new StringContent("postcode"), "columns");

        multipartContent.Add(new StringContent("result_id"), "result_columns");

        multipartContent.Add(new StringContent("score"), "result_columns");

        request.Content = multipartContent; 


        var response = await httpClient.SendAsync(request);

    }

}

But i don't succeed to run it.

And normally the POST action is planned to managed that instead of reinvented the wheel with C# code.
 
So nobody has an idea to succeed that ?
 
You need to send POST request with multipart data (file in it)
I think you should just google more about post requests with multpart and how to pass a file in it.
 
Hi, @cherubin quick forum search gave me this: https://zennolab.com/discussion/thr...om-post-multipart-form-data.94637/post-633809

You can try it. But there are other example on the forum using default zenno cubes.

What keyword did you use ? I don't know any russian words.

I find thanks Google & ChatGPT some solutions with C#, however i thought the POST action was designed to manage that kind of thing. But i don't succeed. And i tried multipart as file since the begining, without success, so i tried every option i found but i failed. That's why i'm here to ask.
And it seems the final solution is to use a specific code in a C# block.
 
Well, I can not answer what exactly is the problem with your task. Maybe this is related to the page itself. When I try to go to this url, it does not even load api-uploadcsv.com By uploading file and tracking this manually you can get more information with help of Fiddler. Thats how you usually build request. Fidler will give you more information of what is needed to upload file in your particular case.
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)