You should be able to set your Upload Data to Specify Upload Body and set the Upload Body to an attribute.
I've tried doing that but I think the HTTPCaller is overriding things behind the scenes.
I've set my Content-Type header value to multipart/form-data and my body is:
)
Content-Disposition: form-data; name="fileProperties"
Content-Type: application/json
@Value(_filePropertiesJSON)
)
Content-Disposition: form-data; name="fileContent"; filename="@Value(_pwFile_filename)"
Content-Type: text/plain
@Value(upload_file_content)
)--
but the error that I'm getting back from the service that I'm calling is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid Header</h2>
<hr><p>HTTP Error 400. The request has an invalid header name.</p>
</BODY></HTML>
The only header value that I'm trying to set is Content-Type and its value is:
multipart/form-data; charset=utf-8; )
Ideally, what I would like is an option on the HTTPCaller to allow me to select the Upload Data type to be multipart/form-data and then to select the file contents part to be supplied by an attribute.
Rylan at Safe Software support helped me out with this. Unfortunately, I wasn't able to get my particular use-case to work because it seems like there's a bug in the API that I'm trying to use. However, as a general rule, it should be possible to upload file content from an attribute in a multipart/form-data upload.
The HTTPCaller settings will look something like this:
The important points to note here being the "Content-Type" and "Content-Length" headers and the Upload Data being set to "Specify Upload Body".
The format of the upload body content will vary a little depending on the API you're calling but will be something like:
--<your boundary text>
Content-Type: application/json; charset=UTF-8
{
"attr_name": "attr_value"
}
--<your boundary text>
Content-Type: image/jpeg
@Value(_file_contents)
--<your boundary text>--
Hope this helps someone....
I just thought I'd provide some more insight to this issue, it took a savvy FME user, a pretty advanced web developer and searching many Stackoverflow solutions to get the HTTPCaller parameters to line up with Google Docs API documentation and come up with the solution.
https://developers.google.com/drive/api/v3/manage-uploads
https://developers.google.com/drive/api/v3/multipart-upload
https://developers.google.com/drive/api/v3/folder
https://stackoverflow.com/questions/12889532/insert-a-file-to-a-particular-folder-using-google-drive-api/12889786
https://gist.github.com/tanaikech/bd53b366aedef70e35a35f449c51eced#sample-script-2
This HTTPCaller writes an XLS file to a Google Drive folder and converts it to a Google Sheet. There are two required Query Strings: "upload", and "convert".
Three different Content/MIME types: Header "Content-Type" (above), metadata MIME Type, and media MIME Type.
Lastly the order of the Multipart Upload matters. I hope this helps others.
Rylan at Safe Software support helped me out with this. Unfortunately, I wasn't able to get my particular use-case to work because it seems like there's a bug in the API that I'm trying to use. However, as a general rule, it should be possible to upload file content from an attribute in a multipart/form-data upload.
The HTTPCaller settings will look something like this:
The important points to note here being the "Content-Type" and "Content-Length" headers and the Upload Data being set to "Specify Upload Body".
The format of the upload body content will vary a little depending on the API you're calling but will be something like:
--<your boundary text>
Content-Type: application/json; charset=UTF-8
{
"attr_name": "attr_value"
}
--<your boundary text>
Content-Type: image/jpeg
@Value(_file_contents)
--<your boundary text>--
Hope this helps someone....
For the example you've mentioned, how do you attach an actual file right after line 10 (Content-Type: image/jpeg ) if it's not in an attribute?