Bulk uploads is a more convenient way to upload multiple files to mediacast that can be used instead of repetitively upload files via web browser.
curl is a handy tool that can be used to download or upload files over http, ftp and other protocols. Since mediacast is just an http service, curl can be used to upload files to mediacast too.
In order to be able to upload files to mediacast one must tell curl (or another http tool) how to create the correct request that mediacast will understand as an upload request. Such a request consists of HTTP headers and HTTP parameters.
Required Headers
| Name | Description | Allowed Values |
|---|---|---|
| Sec-Mediacast | Flag header that turns of CSRF protection | Must always be true |
| Cookie - CWP_SESSION | Cookie containing a valid CWPID session ID | string |
CWP_SESSION value can be obtained by:
# create password file
$ touch password.txt
$ chmod og-rwx password.txt
$ vi password.txt
$ curl -X POST \
-c cookies.txt \
-d IDToken1=<your user name> \
-d IDToken2=`cat password.txt` \
-d program=portal -d "goto=http://mediacast.sun.com/" \
-o /dev/null \
https://identity.sun.com/amserver/UI/Login
The CWP_SESSION id is stored in the cookies.txt file.
After all the uploads are done, you should delete the cookies and password files:
$ rm cookies.txt $ rm password.txt
Required Form Parameters
| Name | Description | Allowed Values |
|---|---|---|
| media[name] | User-friendly name of the record. | string, unique for user, 1..64 chars |
| media[description] | Description of the record. | string, 1..1024 chars |
| media[tag_names] | Tags associated with the record. | comma or space separated string of tags |
| media[class] | Flag parameter | must be MediaFile for file uploads |
| uploaded_file | Form encoded content of the file that is being uploaded | string |
curl Example
$ curl -X POST \
-F media[name]="<some user friendly name>" \
-F media[description]="<file description>" \
-F media[tag_names]="<tag>, <tag>, <tag>" \
-F media[class]=MediaFile \
-b cookies.txt \
-H Sec-Mediacast:true \
-F uploaded_file=@/path/to/file \
http://mediacast.sun.com/users/<screen name here>/new
Alternatively the cookie can be specified as a string: -b CWP_SESSION=<session id here>
Example:
$ curl -X POST \
-F media[name]="Some Fancy Name" \
-F media[description]="This is a fancy file" \
-F media[tag_names]="fancy, test" \
-F media[class]=MediaFile \
-b cookies.txt \
-H Sec-Mediacast:true \
-F uploaded_file=@/path/to/file \
http://mediacast.sun.com/users/IgorMinar/new
Optional Form Parameters
| Name | Description | Allowed Values | Default |
|---|---|---|---|
| media[open_upon_download] | Controls how the file download is handled by the browser/client. If true browsers will try to open the file, otherwise they will just download the file | true, false | true |
| media[filename] | The filename that will be sent to clients during download. This is to allow the filename to differ from the name of the uploaded file |
/^[\w\-+_]+[\w\-+_\. ]+[\w\-+_]$/ uniq for user, 1..64 chars |
the name of the file being uploaded |
| media[permalink] | the ID string of the file exposed in the download URI as its last component |
/^[\w\-+_\.]+$/ uniq for user, 1..64 chars |
sanitized filename |
Comments (8)
Apr 02, 2009
am74686 says:
Looking forward to using this but I'm facing a redirect when trying to upload (H...Looking forward to using this but I'm facing a redirect when trying to upload (HTML code reported by curl) and no apparent. Doesn't curl follow redirects by default? Also, your second code example does not use CWP_SESSION and uses your screen name.
Apr 14, 2009
IgorMinar says:
hmm.. not sure why you are getting an html error.. can you email me the html? Th...hmm.. not sure why you are getting an html error.. can you email me the html? The api is just a quick hack to make bulk uploads possible. A much better solution is in works.
The second example doesn't use CWP_SESSION because it is read from the cookies.txt file and the example uses my name because it is an example, you should replace the name with your screen name when uploading stuff.
Let me know if you still have issues with this.
May 05, 2009
DavePickens says:
I keep getting redirected when I do this. I've successfully downloaded the cooki...I keep getting redirected when I do this. I've successfully downloaded the cookie from identity.sun.com but when I attempt to upload mediacast.sun.com replies that it is redirecting me back to identity.sun.com
May 09, 2009
IgorMinar says:
Looks like you are not passing in the session cookie value or the cookie file.Looks like you are not passing in the session cookie value or the cookie file.
May 11, 2009
DavePickens says:
Following the example above as best I can... FYI... in the obtain CWP_SESSION e...Following the example above as best I can...
FYI... in the obtain CWP_SESSION example, it should be "password.txt" everywhere, not just "password"
$ touch password.txt
$ chmod og-rwx password.txt
Cookie file is created and appears correct.
May 11, 2009
IgorMinar says:
thanks for the typo report.. it's fixed now. Can you please create a servicede...thanks for the typo report.. it's fixed now.
Can you please create a servicedesk ticket and post details about the command you are using as well as your login name and time when the last error occurred? I just went through the steps and was able to upload a file successfully, so I'm wondering if there is something wrong with your account or the command you are using. thanks
Jul 02
Brian_Leonard says:
Hi Igor, I am experiencing the same redirect issue as Dave. Under what category...Hi Igor,
I am experiencing the same redirect issue as Dave. Under what category should I file the Service Desk issue?
Thanks,
Brian
Jul 02
IgorMinar says:
Hi Brian, if you use "Search Tasktype" and enter "mediacast", you'll find the q...Hi Brian,
if you use "Search Tasktype" and enter "mediacast", you'll find the queue.
/i