Using HTTPPost To Send A File
"Mike Bannon" <mikeb@...>
Hi All
I need to send a CSV file to a via a URL to an API server. So, I’m compiling the CSV as a Blob, then using HTTPPost to send it.
The post is being rejected because, they say, “the content type is not flagged as being of type ‘file’”. Within the syntax of HTTPPost there is no obvious way of setting a content type. Has anyone come across this or know a solution?
TIA Mike Bannon DataFormation Ltd., UK
|
|
Craig Martin <craig@...>
I don't have a Magic ready-made solution for that but if you google for a combination of multipart/form-data and upload file via POST or HTTPWebRequest or some phrases like that you'll get an idea for what you must do - which will include converting the file to base64 - basically you'll be doing exactly what a web-browser does for file upload, all good To: magicu-l@... From: mikeb@... Date: Fri, 11 Apr 2014 14:45:36 +0100 Subject: [magicu-l] Using HTTPPost To Send A File Hi All
I need to send a CSV file to a via a URL to an API server. So, I’m compiling the CSV as a Blob, then using HTTPPost to send it.
The post is being rejected because, they say, “the content type is not flagged as being of type ‘file’”. Within the syntax of HTTPPost there is no obvious way of setting a content type. Has anyone come across this or know a solution?
TIA Mike Bannon DataFormation Ltd., UK
|
|
Andreas Sedlmeier <sedlmeier@...>
Hi Mike,
You need to tell the server what the content type is and eventually encode
the file. That’s depends on what they do accept.
If they accept everything you just have to set the correct content type and
for .csv it could be “application/csv”. If the backend accepts that content type
you simply create the .csv and upload with following command:
HttpPost (‘http://fileuplad.whoever.test/’, File2Blb(‘c:\temp\test.csv’,
‘Content-type: application/csv’)
If the backend f.i. is designed to handle
Form-based file upload (http://www.ietf.org/rfc/rfc1867.txt) only
(that what browsers do when you press uplad file buttons) you’ll have to encode
the file.
Encoding the file is a bit tedious with Magic. I suggest that you do use
f.i. CURL (http://curl.haxx.se/) for the upload then. This is a
library and a command line tool and uploading your .csv is as simple as
this:
curl -X POST -d @c:\temp\test.csv http://fileuplad.whoever.test/
Best regards,
Andreas
From: Mike Bannon
Sent: Friday, April 11, 2014 3:45 PM
To: Magic Mail List
Subject: [magicu-l] Using HTTPPost To Send A File Hi All
I need to send a CSV file to a via a URL to an API server. So, I’m compiling the CSV as a Blob, then using HTTPPost to send it.
The post is being rejected because, they say, “the content type is not flagged as being of type ‘file’”. Within the syntax of HTTPPost there is no obvious way of setting a content type. Has anyone come across this or know a solution?
TIA Mike Bannon DataFormation Ltd., UK
|
|
"Mike Bannon" <mikeb@...>
Thanks for your quick responses, Andreas & Craig
Assuming that they can accept the application/csv type, and given that I already have the CSV as a blob – I’ve just concatenated it from the data – is there any reason to use Blob2File then File2Blob, or can I just pass the original blob?
Thanks Mike
From: magicu-l@... [mailto:magicu-l@...] On Behalf Of Andreas Sedlmeier
Sent: 11 April 2014 15:27 To: Magic Mail List Subject: Re: [magicu-l] Using HTTPPost To Send A File
Hi Mike,
You need to tell the server what the content type is and eventually encode the file. That’s depends on what they do accept.
If they accept everything you just have to set the correct content type and for .csv it could be “application/csv”. If the backend accepts that content type you simply create the .csv and upload with following command: HttpPost (‘http://fileuplad.whoever.test/’, File2Blb(‘c:\temp\test.csv’, ‘Content-type: application/csv’)
If the backend f.i. is designed to handle Form-based file upload (http://www.ietf.org/rfc/rfc1867.txt) only (that what browsers do when you press uplad file buttons) you’ll have to encode the file.
Encoding the file is a bit tedious with Magic. I suggest that you do use f.i. CURL (http://curl.haxx.se/) for the upload then. This is a library and a command line tool and uploading your .csv is as simple as this: curl -X POST -d @c:\temp\test.csv http://fileuplad.whoever.test/
Best regards,
Andreas
From: Mike Bannon Sent: Friday, April 11, 2014 3:45 PM To: Magic Mail List Subject: [magicu-l] Using HTTPPost To Send A File
Hi All
I need to send a CSV file to a via a URL to an API server. So, I’m compiling the CSV as a Blob, then using HTTPPost to send it.
The post is being rejected because, they say, “the content type is not flagged as being of type ‘file’”. Within the syntax of HTTPPost there is no obvious way of setting a content type. Has anyone come across this or know a solution?
TIA Mike Bannon DataFormation Ltd., UK
|
|
Andreas Sedlmeier <sedlmeier@...>
No, you can use the blob which you do already have. No need to write it to
disk first. If they do reject “application/csv” and you have a contact there,
just ask what content types they actually do support if there’s no
documentation. If it’s a REST API there should be some documentation like
following f.i.: http://pic.dhe.ibm.com/infocenter/dmndhelp/v7r5mx/index.jsp?topic=%2Fcom.ibm.wbpm.bpc.doc%2Ftopics%2Fcdev_restapis_contenttypes.html
From: Mike Bannon
Sent: Friday, April 11, 2014 4:39 PM
To: magicu-l@...
Subject: RE: [magicu-l] Using HTTPPost To Send A
File Thanks for your quick responses, Andreas & Craig
Assuming that they can accept the application/csv type, and given that I already have the CSV as a blob – I’ve just concatenated it from the data – is there any reason to use Blob2File then File2Blob, or can I just pass the original blob?
Thanks Mike
From:
magicu-l@... [mailto:magicu-l@...] On Behalf Of
Andreas Sedlmeier
Hi Mike,
You need to tell the server what the content type is and eventually encode the file. That’s depends on what they do accept.
If they accept everything you just have to set the correct content type and for .csv it could be “application/csv”. If the backend accepts that content type you simply create the .csv and upload with following command: HttpPost (‘http://fileuplad.whoever.test/’, File2Blb(‘c:\temp\test.csv’, ‘Content-type: application/csv’)
If the backend f.i. is designed to handle Form-based file upload (http://www.ietf.org/rfc/rfc1867.txt) only (that what browsers do when you press uplad file buttons) you’ll have to encode the file.
Encoding the file is a bit tedious with Magic. I suggest that you do use f.i. CURL (http://curl.haxx.se/) for the upload then. This is a library and a command line tool and uploading your .csv is as simple as this: curl -X POST -d @c:\temp\test.csv http://fileuplad.whoever.test/
Best regards,
Andreas
From: Mike Bannon Sent: Friday, April 11, 2014 3:45 PM To: Magic Mail List Subject: [magicu-l] Using HTTPPost To Send A File
Hi All
I need to send a CSV file to a via a URL to an API server. So, I’m compiling the CSV as a Blob, then using HTTPPost to send it.
The post is being rejected because, they say, “the content type is not flagged as being of type ‘file’”. Within the syntax of HTTPPost there is no obvious way of setting a content type. Has anyone come across this or know a solution?
TIA Mike Bannon DataFormation Ltd., UK
|
|
Anton Doank
hi mike, did your problem fixed? Do you have solution for this? I have same case with you, i want to send a file using httppost.
|
|