cURL / Mailing Lists / curl-users / Single Mail

curl-users

write different files to disk from an multipart/x-mixed-replace; boundary=END

From: Yaron Illouz <yaroni_at_radcom.com>
Date: Tue, 30 Jun 2015 20:37:43 +0300

Hi

 

Hi am trying to get multiple files from a http post reponse.

I know how to write the response as one file but I don't know how to
write it as different files to disk.

How do I write the file that arrive in the answer as different files?

For now the output is written to screen as one part (with the --END)

The request is sent from c++ code using curl

    CURL *curl;
    FILE *fp;
    CURLcode res;
 
    curl = curl_easy_init();
    if(curl)
    {
            //fp = fopen(pi_sRequests.c_str(),"wb");
            struct curl_slist *headers=NULL;
 
//headers = curl_slist_append(headers, "Content-Type:
multipart/x-mixed-replace;boundary=END");
            curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers );
 
            curl_easy_setopt(curl, CURLOPT_URL,
"http://172.16.5.178:8080/module/FileServlet");
            curl_easy_setopt(curl,
CURLOPT_POSTFIELDS,pi_sRequests.c_str());
            //curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
write_to_file);
            //curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
            res = curl_easy_perform(curl);
 
            /* always cleanup */
            curl_easy_cleanup(curl);
            //fclose(fp);
    }

The response arrive from code writen in java. I took code from Can i
attach multiple attachments in one HttpServletResponse
<http://stackoverflow.com/questions/19441463/can-i-attach-multiple-attac
hments-in-one-httpservletresponse>

response.setContentType("multipart/x-mixed-replace;boundary=END");
ServletOutputStream out = response.getOutputStream();
out.println("--END");
for(File f:files){
      FileInputStream fis = new FileInputStream(file);
      BufferedInputStream fif = new BufferedInputStream(fis);
      int data = 0;
      out.println("--END");
      while ((data = fif.read()) != -1) {
        out.write(data);
      }
      fif.close();
      out.println("--END");
      out.flush();
}
out.flush();
out.println("--END--");
out.close();

 

 

My question is also on stackoverflow
http://stackoverflow.com/questions/31144560/write-multiple-file-from-a-p
ost-reponse-with-curl

 

 

 

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-06-30