<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Facing issues in creating multipart http request for uploading files</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119136/facing-issues-in-creating-multipart-http-request-for-uploading-files</link><description>Hello, I was trying to execute multipart request for uploading log files. For testing the multipart that how does it works first I made a server through python script which I linked with ngrok so that other people can also upload files. Than I tried sending</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 13 May 2025 10:50:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119136/facing-issues-in-creating-multipart-http-request-for-uploading-files" /><item><title>RE: Facing issues in creating multipart http request for uploading files</title><link>https://devzone.nordicsemi.com/thread/535084?ContentTypeID=1</link><pubDate>Tue, 13 May 2025 10:50:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:648d89ed-f392-476f-9e91-ca838c08a8ea</guid><dc:creator>Rakshita</dc:creator><description>&lt;p&gt;Hi&lt;br /&gt;U can close this ticket it was solved&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Facing issues in creating multipart http request for uploading files</title><link>https://devzone.nordicsemi.com/thread/524103?ContentTypeID=1</link><pubDate>Fri, 21 Feb 2025 13:47:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0eea777-afba-46bb-abf3-545bc3fd7a07</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I see that it returns -1 here:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00:01:36.319,030] &amp;lt;err&amp;gt; home_demo_https: Send error, abort
[00:01:36.319,335] &amp;lt;err&amp;gt; home_demo_https: Failed to send upload file HTTP req, err: -1
..&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Is this still due to your buffers being filled up?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you try to adjust your net buffers?&lt;/p&gt;
&lt;p&gt;By setting CONFIG_NET_BUF_VARIABLE_DATA_SIZE=y, you can set a combined buffer via:&lt;/p&gt;
&lt;p&gt;CONFIG_NET_BUF_DATA_POOL_SIZE=8192&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Or with never SDKs, where its split into RX and TX:&lt;/p&gt;
&lt;p&gt;CONFIG_NET_PKT_BUF_RX_DATA_POOL_SIZE=4096&lt;/p&gt;
&lt;p&gt;CONFIG_NET_PKT_BUF_TX_DATA_POOL_SIZE=6144&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;(feel free to change the sizes)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Facing issues in creating multipart http request for uploading files</title><link>https://devzone.nordicsemi.com/thread/523941?ContentTypeID=1</link><pubDate>Thu, 20 Feb 2025 15:31:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42c1152d-114d-44ac-a49f-771c9bcb2b97</guid><dc:creator>Rakshita</dc:creator><description>&lt;p&gt;Yes I tried adding it but it throws -104 error&amp;nbsp;&lt;br /&gt;I also came across&amp;nbsp;&lt;a id="" href="https://hacod.tech/blog/sending-files-to-aws-s3-bucket-using-zephyr-rtos-http-api"&gt;https://hacod.tech/blog/sending-files-to-aws-s3-bucket-using-zephyr-rtos-http-api&lt;/a&gt;&lt;br /&gt;which doesn&amp;#39;t mention any particular content-type but when I added this in my code I was getting&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;[00:01:36.222,381] &amp;lt;inf&amp;gt; home_demo_sdcard: Wrote 2220 bytes to file /SD:/home2.bin

[00:01:36.229,705] &amp;lt;inf&amp;gt; home_demo_sdcard: 
Listing dir /SD: ...

[00:01:36.230,102] &amp;lt;inf&amp;gt; home_demo_sdcard: Full filename: /SD:/home2.bin
[00:01:36.231,781] &amp;lt;inf&amp;gt; home_demo_sdcard: File size: 2220 bytes

[00:01:36.232,116] &amp;lt;inf&amp;gt; home_demo_sdcard: File check 2 2
[00:01:36.232,513] &amp;lt;dbg&amp;gt; net_http_client: http_flush_data: Data to send
                                          50 55 54 20 2f 75 70 6c  6f 61 64 20 48 54 54 50 |PUT /upl oad HTTP
                                          2f 31 2e 31 0d 0a 48 6f  73 74 3a 20 65 66 63 66 |/1.1..Ho st: efcf
                                          2d 31 30 36 2d 35 31 2d  36 38 2d 31 38 37 2e 6e |-106-51- 68-187.n
                                          67 72 6f 6b 2d 66 72 65  65 2e 61 70 70 0d 0a 43 |grok-fre e.app..C
                                          6f 6e 74 65 6e 74 2d 4c  65 6e 67 74 68 3a 20 7a |ontent-L ength: z
                                          75 0d 0a 0d 0a                                   |u....            
[00:01:36.240,203] &amp;lt;inf&amp;gt; home_demo_https: Sent 1024 bytes
[00:01:36.245,697] &amp;lt;inf&amp;gt; home_demo_https: Sent 1024 bytes
[00:01:36.319,030] &amp;lt;err&amp;gt; home_demo_https: Send error, abort
[00:01:36.319,335] &amp;lt;err&amp;gt; home_demo_https: Failed to send upload file HTTP req, err: -1
[00:01:36.623,229] &amp;lt;inf&amp;gt; home_demo_https: CSemCount 0
[00:01:38.745,208] &amp;lt;inf&amp;gt; home_demo_uart: Sensor index 0
[00:01:41.319,732] &amp;lt;err&amp;gt; home_demo_sdcard: Failed to send request&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;the attached error&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Facing issues in creating multipart http request for uploading files</title><link>https://devzone.nordicsemi.com/thread/523933?ContentTypeID=1</link><pubDate>Thu, 20 Feb 2025 14:50:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4080ae96-1449-4c92-a8c7-33040c2d0717</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Rakshita"]Also&amp;nbsp;after enabling NET_LOG and NET_HTTP_LOG I came to know that I was getting data allocation failed, so I increased the CONFIG_NET_BUF_DATA_SIZE=1024 from 256[/quote]
&lt;p&gt;Good to hear that you have gotten the buffering issue resolved.&lt;/p&gt;
[quote user="Rakshita"]I observed that it doesn&amp;#39;t&amp;nbsp;adds the BOUNDARY in the request automatically&lt;br /&gt;So does it needs to be done manually[/quote]
&lt;p&gt;That looks to be a functionality that the http_client_req() does not add for you. Have you tried adding this to your req.headers?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Facing issues in creating multipart http request for uploading files</title><link>https://devzone.nordicsemi.com/thread/523852?ContentTypeID=1</link><pubDate>Thu, 20 Feb 2025 09:57:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb03f17d-8e6f-42b0-bc67-5275faf3a5ee</guid><dc:creator>Rakshita</dc:creator><description>&lt;p&gt;I tried removing the multipart_header and multipart_footer and just kept a simple header with the filename being in the payload&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;int logsUpload_req(char *filename)
{
	int err = 0;	
	
	///Define the structure http_request and fill the block of memory 
	struct http_request req;
	memset(&amp;amp;req, 0, sizeof(req));
	const char *headers[] = {
        &amp;quot;Connection: keep-alive\r\n&amp;quot;,
        &amp;quot;Host: 148a-106-51-226-188.ngrok-free.app\r\n&amp;quot;,
        &amp;quot;Content-Type: form-data\r\n&amp;quot;,
        NULL
    };
	req.header_fields = headers;
	req.method = HTTP_POST;
	req.url = &amp;quot;/upload&amp;quot;;
	req.host = LOG_HOSTNAME;
	req.protocol = &amp;quot;HTTP/1.1&amp;quot;;
	req.payload = filename;
	req.payload_len = bytes_read;
	req.response = logsUpload_cb;
	req.recv_buf = recv_buf;
	req.recv_buf_len = sizeof(recv_buf);
    err = http_client_req(sock, &amp;amp;req, 7000, NULL);
    if (err &amp;lt; 0) {
        LOG_ERR(&amp;quot;Failed to send upload file HTTP req, err: %d&amp;quot;, err);
        return err;
    }		
	return err;
}&lt;/pre&gt;&lt;br /&gt;Also&amp;nbsp;after enabling NET_LOG and NET_HTTP_LOG I came to know that I was getting data allocation failed, so I increased the CONFIG_NET_BUF_DATA_SIZE=1024 from 256&lt;br /&gt;&lt;br /&gt;I am getting&amp;nbsp;&lt;br /&gt;[00:01:46.232,757] &amp;lt;dbg&amp;gt; net_http_client: http_flush_data: Data to send&lt;br /&gt; 50 4f 53 54 20 2f 75 70 6c 6f 61 64 20 48 54 54 |POST /up load HTT&lt;br /&gt; 50 2f 31 2e 31 0d 0a 48 6f 73 74 3a 20 31 34 38 |P/1.1..H ost: 148&lt;br /&gt; 61 2d 31 30 36 2d 35 31 2d 32 32 36 2d 31 38 38 |a-106-51 -226-188&lt;br /&gt; 2e 6e 67 72 6f 6b 2d 66 72 65 65 2e 61 70 70 0d |.ngrok-f ree.app.&lt;br /&gt; 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 |.Connect ion: kee&lt;br /&gt; 70 2d 61 6c 69 76 65 0d 0a 48 6f 73 74 3a 20 31 |p-alive. .Host: 1&lt;br /&gt; 34 38 61 2d 31 30 36 2d 35 31 2d 32 32 36 2d 31 |48a-106- 51-226-1&lt;br /&gt; 38 38 2e 6e 67 72 6f 6b 2d 66 72 65 65 2e 61 70 |88.ngrok -free.ap&lt;br /&gt; 70 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a |p..Conte nt-Type:&lt;br /&gt; 20 66 6f 72 6d 2d 64 61 74 61 0d 0a 43 6f 6e 74 | form-da ta..Cont&lt;br /&gt; 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 32 32 32 30 |ent-Leng th: 2220&lt;br /&gt; 0d 0a 0d 0a |.... &lt;br /&gt;[00:01:46.242,095] &amp;lt;dbg&amp;gt; net_http_client: http_client_req: (0x20004090): Sent 2400 bytes&lt;br /&gt;[00:01:46.286,285] &amp;lt;dbg&amp;gt; net_http_client: on_message_begin: (0x20004090): -- HTTP POST response (headers) --&lt;br /&gt;[00:01:46.286,773] &amp;lt;dbg&amp;gt; net_http_client: on_status: (0x20004090): HTTP response status 400 Bad Request&lt;br /&gt;[00:01:46.289,093] &amp;lt;dbg&amp;gt; net_http_client: print_header_field: (0x20004090): [14] Content-Length&lt;br /&gt;[00:01:46.290,954] &amp;lt;dbg&amp;gt; net_http_client: print_header_field: (0x20004090): [2] 11&lt;br /&gt;[00:01:46.291,961] &amp;lt;dbg&amp;gt; net_http_client: print_header_field: (0x20004090): [10] Connection&lt;br /&gt;[00:01:46.292,877] &amp;lt;dbg&amp;gt; net_http_client: print_header_field: (0x20004090): [5] close&lt;br /&gt;[00:01:46.293,762] &amp;lt;dbg&amp;gt; net_http_client: print_header_field: (0x20004090): [12] Content-Type&lt;br /&gt;[00:01:46.294,647] &amp;lt;dbg&amp;gt; net_http_client: print_header_field: (0x20004090): [10] text/plain&lt;br /&gt;[00:01:46.295,074] &amp;lt;dbg&amp;gt; net_http_client: on_headers_complete: (0x20004090): Headers complete&lt;br /&gt;[00:01:46.317,626] &amp;lt;dbg&amp;gt; net_http_client: http_wait_data: Connection error (0)&lt;br /&gt;[00:01:46.317,993] &amp;lt;dbg&amp;gt; net_http_client: http_client_req: (0x20004090): Received 0 bytes&lt;br /&gt;&lt;br /&gt;this currently&lt;br /&gt;I observed that it doesn&amp;#39;t&amp;nbsp;adds the BOUNDARY in the request automatically&lt;br /&gt;So does it needs to be done manually&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>