簡體   English   中英

Dropbox(文件放置)API使用哪種內容類型? 以及如何模仿呢?

[英]What content-type does dropbox (file put) api uses? and How to mimic it?

我正在閱讀Dropbox API的files_put文檔。

他們使用的URL路徑為: https://api-content.dropbox.com/1/files_put/<root>/<path>?param=val : https://api-content.dropbox.com/1/files_put/<root>/<path>?param=val <root>/<path> https://api-content.dropbox.com/1/files_put/<root>/<path>?param=val ,請求正文保存該文件:

必需要上載的文件內容。 由於整個PUT主體將被視為文件,因此任何參數都必須作為請求URL的一部分傳遞。 應該像對其他OAuth請求URL進行簽名一樣,對請求URL進行簽名。

問題

  • 我很好奇這種請求的內容類型是什么? (請求正文中的文件和url字符串中的參數)

  • 該API功能如何模仿? 特別是在grails控制器中。 這樣的事情。

  • 如何在cURL Update中測試這種類型的請求:我在這里找到了如何使用curl測試它。

對於控制器,我設想了這樣的事情

  def save () {
    withFormt {
      html {actForHTML}
      <something> {actForREST}
    }
  }

  def actForREST () {
     //how can I get access to the file? I guess url parameters can be accessed by `params`
  }

REST控制台無法在請求正文中發送二進制數據。 不幸的是,我現在無法訪問curl 但是我為您提供的輸入很少,而且我還將在我的個人計算機上嘗試相同的輸入。

  • 如何使用curl進行文件上傳? (@source-cURL文檔)

    4.3文件上傳POST

    早在1995年末,他們定義了另一種通過HTTP發布數據的方法。 它記錄在RFC 1867中,為什么有時將此方法稱為RFC1867發布。

    此方法主要用於更好地支持文件上載。 允許用戶上傳文件的表單可以用HTML編寫如下:

     <form method="POST" enctype='multipart/form-data' action="upload.cgi"> <input type=file name=upload> <input type=submit name=press value="OK"> </form> 

    這清楚地表明即將發送的Content-Type是multipart / form-data。

    要使用curl張貼到這樣的表單,請輸入以下命令行:

      curl --form upload=@localfilename --form press=OK [URL] 
  • W3C規格

    看看這里的W3C規范和multipat / form-data的RFC1867

  • Grails Controller處理請求

    您的應用程序應該能夠處理multipart/form-data (我認為不需要添加MIME類型)。 您在控制器中的操作應如下所示:-

例如:

def uploadFileAndGetParams(){
    def inputStream = request.getInputStream()
    byte[] buf = new byte[request.getHeaders().CONTENT_LENGTH] //Assuming
    //Read the input stream
    for (int chunk = inputStream.read(buf); chunk != -1; chunk = is.read(buf)){
        //Write it any output stream
        //Can refer the content-type of the file (following W3C spec)
        //and create an Output stream accordingly
    }

    //Get the params as well
    //params.foo //params.bar 
}

它可能不是完整的證據,但應該比我想的要簡單。 我今天要嘗試同樣的方法。 有用的帖子看看。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM