1. --!movie
  2. --!encoding=utf-8
  3.  
  4. global $
  5.  
  6. global gCh
  7.  
  8. ----------------------------------------
  9. -- Send data with HTTP PUT method (synchronous or blocking mode)
  10. ----------------------------------------
  11. on startMovie
  12.     _player.debugPlaybackEnabled = 1
  13.  
  14.     -- libs
  15.     $.import("curl")
  16.     $.import("file")
  17.  
  18.     -- config
  19.     tLocalFile = $.PATH & "downloaded.mp3"
  20.  
  21.     -- get a CURL handle (xtra instance)
  22.     gCh = $.curl.init()
  23.  
  24.     -- specify options
  25.     gCh.setOption($.curl.CURLOPT.URL, "http://valentin.dasdeck.com/xtras/curl_xtra/.test/put.php")
  26.     gCh.setOption($.curl.CURLOPT.UPLOAD, 1)
  27.     gCh.setOption($.curl.CURLOPT.NOPROGRESS, 0)
  28.  
  29.     -- required for HTTP PUT upload with progress callback
  30.     -- otherwise progressCallback isn't called!
  31.     gCh.setOption($.curl.CURLOPT.INFILESIZE, $.file.size(tLocalFile))
  32.  
  33.     -- upload this script file
  34.     gCh.setSourceFile(tLocalFile)
  35.  
  36.     -- set callbacks
  37.     gCh.setProgressCallback(#slotCurlProgress)
  38.  
  39.     -- returnMode: 0=return error code (=default), 1=return data, 2=return chunks immediately
  40.     $.curl.execAsyncDetached(gCh, #slotCurlResult)
  41. end
  42.  
  43. ----------------------------------------
  44. -- @callback
  45. ----------------------------------------
  46. on slotCurlResult (res)
  47.     put "ERROR:" && curl_error(res) -- if returnMode=0, res is ALWAYS an error code
  48. --  put "SPEED_UPLOAD:" && gCh.getInfo($.curl.CURLINFO.SPEED_UPLOAD)
  49. --  put "TOTAL_TIME:" && gCh.getInfo($.curl.CURLINFO.TOTAL_TIME)
  50.     gCh = VOID
  51. end
  52.  
  53. ----------------------------------------
  54. -- @callback
  55. ----------------------------------------
  56. on slotCurlProgress (dltotal, dlnow, ultotal, ulnow)
  57.     -- put dltotal, dlnow, ultotal, ulnow
  58.     if ultotal>0 then
  59.         put (ulnow*100/ultotal) && "%"
  60.     end if
  61. end
  62.  
[raw code]