Reputation: 5788
I'm trying to use curl to batch upload to YouTube, following the API spec here; in short, it requires a multipart POST request with metadata in XML format and Content-Type of application/atom+xml; charset=UTF-8
, followed by the video data itself.
My current command line (fetching the metadata from upl.xml and the video from upl.mkv) looks something like this:
curl -s -F "[email protected]" -F "[email protected]" -H 'GData-Version: 2' -H 'Authorization: GoogleLogin auth=<AUTH>' -H 'Slug: upl.mkv' -H 'X-GData-Key: key=<KEY>' http://uploads.gdata.youtube.com/feeds/api/users/default/uploads
When I check the actual request that's being sent with --trace
, it looks as though both files are being sent in the correct order, but the Content-Type of the metadata is set to application/octet-stream
; the upload completes as expected, but YouTube refuses to process the video.
If I try to submit upl.xml with --data
, --data-ascii
, --form-string
etc. I just get an assortment of other errors, which leads me to believe it's down to the incorrect Content-Type. If I ignore the metadata and just send the video file it works fine, but unfortunately this doesn't solve my problem.
Am I missing something here, and if not is it possible to do this without breaking out libcurl?
Upvotes: 31
Views: 17050
Reputation: 58034
First, you can specify the content-type for a part you upload by adding ";type=magic/string". Like for example in your video case:
curl -F "[email protected];type=video/mpeg4" [URL]
(use --trace or --trace-ascii to verify that curl sends exactly what you want it to)
... but this said, I'd guess that it is highly unlikely that the receiving server actually cares about what the client claims the content-type is. Meaning I think the source of your problem is actually not the content-type at all.
Upvotes: 59