2016-10-03 58 views
0

這是我的C#.net代碼。當我創建臨時文檔ID然後我發送文檔進行簽名,然後我收到它的空白文件。我認爲臨時文件編號爲空白文件創建。你能幫忙嗎?如何使用adobe echosign api獲取瞬態文檔ID?

public getDocumentId getTransientDocumentId(string accessToken, string path1,string filename) 
    { 
     getDocumentId objGet = new getDocumentId();     

     var nvc = new NameValueCollection 
     { 
      {"File", path1}, 
      {"Content-Type", "multipart/form-data"}, 
      {"Mime-Type", "application/pdf"}, 
      {"File-Name", filename} 
     }; 

     string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x"); 
     byte[] boundarybytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); 
     byte[] boundarybytesF = System.Text.Encoding.ASCII.GetBytes("--" + boundary + "\r\n"); // the first time it itereates, you need to make sure it doesn't put too many new paragraphs down or it completely messes up poor webbrick. 

     HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("https://api.na1.echosign.com/api/rest/v5/transientDocuments"); 
     wr.Method = "POST"; 
     wr.Headers["Access-Token"] = string.Format(accessToken); 
     wr.Headers["Authorization"] = string.Format("Bearer"); 
     wr.UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17"; 
     wr.KeepAlive = true; 
     wr.Credentials = System.Net.CredentialCache.DefaultCredentials; 
     wr.AllowWriteStreamBuffering = true; 

     wr.ContentType = "multipart/form-data; boundary=" + boundary; 

     Stream rs = wr.GetRequestStream(); 


     bool firstLoop = true; 
     string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}"; 
     foreach (string key in nvc.Keys) 
     { 
      if (firstLoop) 
      { 
       rs.Write(boundarybytesF, 0, boundarybytesF.Length); 
       firstLoop = false; 
      } 
      else 
      { 
       rs.Write(boundarybytes, 0, boundarybytes.Length); 
      } 
      string formitem = string.Format(formdataTemplate, key, nvc[key]); 
      byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem); 
      rs.Write(formitembytes, 0, formitembytes.Length); 
     } 
     rs.Write(boundarybytes, 0, boundarybytes.Length); 
     string headerTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\nContent-Type: {2}\r\n\r\n"; 
     string header = string.Format(headerTemplate, "File", new FileInfo(path1).Name, "application/octet-stream"); 
     byte[] headerbytes = System.Text.Encoding.UTF8.GetBytes(header); 
     rs.Write(headerbytes, 0, headerbytes.Length); 
     FileStream fileStream = new FileStream(path1, FileMode.Open, FileAccess.Read); 
     byte[] buffer = new byte[fileStream.Length]; 
     int bytesRead = 0; 
     while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0) 
     { 
      rs.Write(buffer, 0, bytesRead); 
     } 
     fileStream.Close(); 
     byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n"); 
     rs.Write(trailer, 0, trailer.Length); 
     rs.Close(); 
     try 
     { 
      var httpResponse = (HttpWebResponse)wr.GetResponse(); 
      using (var sr = new StreamReader(httpResponse.GetResponseStream())) 
      { 
       var result = sr.ReadToEnd(); 
       var jsonSerialization = new JavaScriptSerializer(); 
       var dictObj = jsonSerialization.Deserialize<Dictionary<string, dynamic>>(result); 

       if (dictObj.Count > 0) 
       { 
        objGet.transientDocumentId = Convert.ToString(dictObj["transientDocumentId"]); 
        objGet.success = "true"; 
       } 
       else 
       { 
        objGet.success = "false"; 
       } 
      }  
     } 
     catch (Exception ex) 
     { 
      objGet.success = "false: " + ex.Message.ToString(); 
     } 
     return objGet; 
    } 
+0

爲什麼不只是發佈相關的代碼,而不是添加所有額外的評論行,這些只會讓你的帖子更難閱讀? – Tavo

+0

檢查它Tavo .. –

回答

0

對於你的目的,你想你已經連接到使用transientDocument協議的文件,你可以使用GET /agreements/{agreementId}/documents API調用這些文件。

但正如問題所述「如何獲取臨時文檔」。那麼,您無法使用任何API獲取transientDocument,原因是transientDocument僅用於臨時目的,通常用於創建單個協議並且是短暫的(僅7天)。如果你想被重用上傳文件創建多個協議,並能獨立獲得其文檔,您應該創建libraryDocument而是採用POST /libraryDocument

可以做得到這些庫文件API調用到那裏的各種細節,如文檔,審計跟蹤等Here是您可以按照以獲得對圖書館文檔更多理解的文檔鏈接