2016-12-21 3 views
0

보관 용 계정을 사용하면 Dropbox 폴더로 URL을 드래그 앤 드롭하여 바로 가기를 만들 수 있습니다. 이것은 다음과 같이 저장됩니다 : raw data returned from dropboxHTTP를 사용하여 드롭 박스 API에서 다운로드 한 BLOB 읽기

당신은 단지를 잡을 수 있도록 당신이 응답을 구문 분석 방법은 다음과 같습니다 example of a url in dropbox

이런 식으로 뭔가를 보이는 XHR 응답을 반환합니다 드롭 박스에서 /2/files/download HTTP API를 사용하여 URL을 클릭 할 수있는 링크로 만드시겠습니까?

+0

[가교 참조 : https://www.dropboxforum.com/t5/API-support/Get-the-URL-path-from-a-link-bookmark-url-file/mp/199000 # M9218] – Greg

답변

0

여기 Angular 1 공장에 들어가야하는 것이 있습니다. 이를 사용하려면 컨트롤러에서 downloadFile 함수를 호출하고 보관 용 계정에있는 파일의 경로를 제공하면됩니다.

function downloadFile(filePath) { 
      if (!filePath) { 
       console.error('Cannot download file because no file was specified.'); 
       return; 
      } 
      return $q(function(fulfill, reject) { 
       $http({ 
        url: 'https://content.dropboxapi.com/2/files/download', 
        method: 'POST', 
        headers: { 
         'Authorization': 'Bearer {{access-token-goes-here}}', 
         'Dropbox-API-Arg': `{"path": "${filePath}"}` 
        }, 
        responseType: 'blob' 
       }).then(
        results => { 
         // data received from dropbox is binary data saved as a blob 
         // The FileReader object lets web applications asynchronously read the contents of files 
         // https://developer.mozilla.org/en-US/docs/Web/API/FileReader 
         var fileReader = new FileReader(); 
         // function will run after successfully reading the file 
         fileReader.onload = function() { 
          var string = this.result; // store the file contents 
          string = encodeURI(string); // get rid of the paragraph return characters 
          var endPosition = string.indexOf('%0D%0A', 32); // find the end of the URL, startPosition is 32 
          var actualURL = string.substring(32, endPosition); // grab only the characters between start and end positions 
          fulfill(actualURL); 
         }; 
         fileReader.readAsText(results.data);       
        }, 
        error => reject(error)); 
      }); 
     } 
+0

그런데 잠재적으로 포함될 수있는 다른 것들이있는 것처럼 보이기 때문에 32 번 위치에서 시작하는 원하는 URL 데이터에 의존하는 것과는 반대로 데이터를 완전히 구문 분석하는 것이 좋습니다. 예 :이 비공식 안내서 참조 : http://www.lyberty.com/encyc/articles/tech/dot_url_format_-_an_unofficial_guide.html – Greg

관련 문제