如何正确使用“ blob”和“ formdata”?

时间:2019-09-26 23:31:45

标签: android file cordova upload

<script>
  function uploadPhoto() {
      var imageURI = document.getElementById('msg').textContent;
      var fd = new FormData();
      window.resolveLocalFileSystemURL(imageURI, function(fileEntry) {
          fileEntry.file(function(file) {
              var reader = new FileReader();
              reader.onloadend = function(e) {
                  var imgBlob = new Blob([this.result], {type:"image/jpeg"});
                  fd.append('file', imgBlob);
                  fd.append('title', 'testing');
                  fd.append('desc', 'testing123');
                  fd.append('content', 'testing12345');
                  console.log(fd);

                  var request = new XMLHttpRequest();
                  request.open('POST', 'http://some_site.com/upload.php');
                  request.send(fd);
              };
              reader.readAsArrayBuffer(file);
          }, function(e){window.alert('error getting file');});
      }, function(e){window.alert('error resolving fs url');});
  }
</script>

它说它已上载,但服务器上没有收到。这里的imageURI是图像的路径,我没有问题。

0 个答案:

没有答案