API: Browser-based uploads

Browser-based uploading consists of two API methods:

This approach is designed to allow API consumers to pre-authenticate uploads to their 23 sites -- and enables applications to let users upload photos and videos to 23 using browser-based uploading. This scheme allows you to accept uploads from users without ever having to proxy or host the files from you server. You should opt for this approach to uploading if you do not want to host or store the uploaded files.

This process also allow for mulri-file uploads via Flash, Gears, Silverlight, HTML5 and other similar endeavors. For Flash specifically, you will need to be aware of our cross-domain acces policies or host the .swf file on your 23 Video domain.


1. Post upload meta data to 23

Start by posting title, description, album, tags and publish status to the API alongside a return_url where the user is returned after uploading the actual file:

http://videos.examples.com/api/photo/get-upload-token?
  title=My+title&
  album_id=12345&
  return_url=http://www.example.com/upload/callback?theme=green

This will return you an upload_token plus information about the exact meta data, about the expiration of the token and about how many times the token can be used:

<response status="ok" permission_level="write" 
  message="The upload token is ready to use" cached="0">
  <upload_token>022fe6e3fb42758d6147c539727c5358af3524b1</upload_token>
  <title>A title for the new upload</title>
  <description>... and a prelimiary description</description>
  <publish>1</publish>
  <tags>product:1234, testemonial</tags>
  <user_id>17488</user_id>
  <album_id></album_id>
  <max_uploads>1</max_uploads>
  <valid_minutes>180</valid_minutes>
  <valid_until>1266711372</valid_until>
  <return_url>http://www.example.com/upload/callback?theme=green</return_url>
</response>

In this example, you're getting a token valid for one upload and for 3 hours.


2. Get the upload_token

From this returned information you will need to extract the upload_token. In this case, the token is:

022fe6e3fb42758d6147c539727c5358af3524b1

3. Build the HTML form using the upload_token

Using this token you can now build a simple HTML form for the user.

<form action="http://videos.example.com/api/photo/redeem-upload-token" 
  method="post" enctype="multipart/form-data">
  <input type="hidden" name="upload_token" value="022fe6e3fb42758d6147c539727c5358af3524b1" />
  <input type="file" name="file" />
  <input type="submit" value="Upload video" />
</form>

Of course, if you set the max_uploads parameter, you can also more advanced upload methods for uploading multiple files at once.


4a. Handle the call-back after the upload completes.

The callback URL is defined by the return_url parameter, and the callback request will always take the form of a HTTP 301 redirect to a GET-style address.

The request will always include the upload_token and domain as a parameter. If the upload succeeded, the parameters photo_id, token, tree_id will be included:

http://www.example.com/upload/callback?
  theme=green&
  domain=videos.example.com&
  upload_token=022fe6e3fb42758d6147c539727c5358af3524b1&
  photo_id=12345&
  tree_id=97531&
  token=mhpDudicFtdjz1isvidhnzsgqv3kaske

4b. Handle the call-back on upload errors

On upload failure, the user is sent to the same callback page. The request includes an error_message parameter alongside upload_token and domain. For example:

http://www.example.com/upload/callback?
  theme=green&
  domain=videos.example.com&
  upload_token=022fe6e3fb42758d6147c539727c5358af3524b1&
  error_message=The+file+type+isn't+supported

Uploading through Flash

You can use a method very similar to the method prescribed above for uploading via Adobe Flash (or equivalent technologies). In these cases, you might not be able to control or even make client-side redirects -- for example, Flash won't redirect to return_url after the upload.

To overcome this, set background_return_p=1 when creating the token. This will cause the callback request to be made from the server-side. You can read more about set-up and returns in the relevant documentation.

Comments

  1. Cheap Beats By Dre
    Putin today inaugural Cheap Beats By Dre President of the conference will cost about $ 860,000 Cheap Beats By Dre
    07, 2012 05 10:16 China Radio microblogging Dr Dre beats

    Zhongguang Wang BEIJING, May 7 news New Style Beats (reporter Ji Su Ping) According to Voice of China "CNR News" reported that Beats By Dre for Teams Putin in the Kremlin today sworn in as Russia's new president to expand
    Beats By Dre for Teams his third presidential term. Old faces, new Beats By Dre In-Ear challenges, Putin the next six years, how to Beats By Dr Dre Pro cross the revival of Russia's dream?

    Today's ceremony will be held in the Great Kremlin expected Beats By Dr Dre Solo the process will last 40 minutes. In a few hours, the Kremlin, Putin will Spartak Intrinsic tower below the door into the Kremlin, that door is usually Beats By Dr Dre Solo HD open only in the most solemn national ceremony will be open. Under the auspices of the Russian Federation Constitutional Court, Putin will handle Beats By Dr Dre Studio on a specially crafted constitution above oath, the moment was regarded as Russia's new President officially inauguration start. Putin sworn before the current President Dmitry New Style Beats By Dre Medvedev will make a brief speech, followed by a symbol of the highest rights of the Russian head of state gold chain to Beats by Dre the Putin gold chain is said to be double-headed eagle and St. George's cross of the , the shape of the medal. The new President of the hand will be in the Casque Beats by Dre Constitution of the Russian Federation on oath, the oath after the Casque Monster Beats Russian national anthem played at the same time, Putin will deliver his inaugural speech, an idea be heard for the first Casque Beats By Dre Pro time in the next six-year term. With Palace will be Casque Beats By Dre Solo ringing the 30-gun salute, the new president, Vladimir Putin will be retiring President Medvedev Casque Beats By Dre Solo HD jointly review the presidential guard of honor in the Kremlin. Casque Beats By Dre Studio

    In accordance with the provisions of the Constitution Nouveau Style Beats By Dre of the Russian Federation to participate in the inauguration ceremony of the new president should also, in addition to the incumbent Beats By Dre president, the Federation Council, that is, Parliament House of Lords and all the members of Dr Dre Cuffie the State Duma lower house of Parliament and the Federal Constitutional Court Executive and so on. Prior to the Kremlin said this time Dr Dre Beats will not be considered to invite foreign heads of state to attend the ceremony, which said Jiang Yi, Beats By Dr Dre Cuffie the Chinese Academy of Social Sciences, the Russian expert on the Cuffie Monster Beats by dr dre Russian government is now more likely to want to complete a grand ceremony, to achieve a Nuovo Stile Beats Cuffie smooth handover concerns into the process of Beats by Dre Studio Cuffie ruling in the future.

    However, compared to a low-key approach does not mean Beats by Dre Pro Cuffie that the ceremony and dinner will be sloppy illegible. According Beats by Dre Solo Cuffie to the site of the purchasing department of the Russian government tender documents show, the Government intends to spend about 26 million rubles about $ 860,000 in funds to host a reception to celebrate Putin Beats by Dre Solo HD Cuffie took office, about 1,000 guests when there will be a feast. According to Russian media reports, the banquet menu includes champagne, Speciale On-Ear Edizione Cuffie pickled sturgeon, fried crabs, small servings of vegetables and assorted cocoa coffee, it is said will be provided specifically for the Kremlin vodka.

    May 07, 2012

Add a comment...

Name
E-mail
Web
 
Connect with Faceboook
Content