Transloadit and PhoneGap

别等时光非礼了梦想. 提交于 2019-12-10 10:29:43

问题


I checked out TransloadIt website and it looked like a great service but its Jquery plugin works only with the html form input... this won't really work with my phonegap application. Is there a way to upload Phonegap camera captured image into Transloadit?


回答1:


I know Transloadit, but not Phonegap. Can you do a multipart form post? Transload can accept that without jQuery. If you can use XHR, then this might be a good example for you https://github.com/tim-kos/transloadit_xhr/blob/master/transloadit_xhr.js




回答2:


Have a working phonegap (cordova) app with Transloadit

Transloadit accepts POST data and does not need to be sent via form.

Here is the post data they use on a form:

https://transloadit.com/docs/#the-minimal-integration (scroll down a bit)

<form id="upload-form" action="http://api2.transloadit.com/assemblies" enctype="multipart/form-data" method="POST">
  <input type="hidden" name="params" value="..." />
  <input type="file" name="my_file" />
  <input type="submit" value="Upload">
</form>

What you do is take those variable names and just match them up in the the cordova file transfer plugin: https://github.com/apache/cordova-plugin-file-transfer

var params = {};
params.params = '[signed assembly goes here]';

var ft = new FileTransfer();
ft.upload(fileURL, 
  encodeURI("http://api2.transloadit.com/assemblies"),
  successCallback, failCallback, { params: params });

What I do is obtain a signed assembly via my server (ajax) on demand that has a timestamp on it to get the assembly info ready for the upload securely so you don't give out your private info or just open up your account to be posted into without your consent.

It is a little more involved because I also have a callback URL setup for transloadit once the assembly is processed. It then has to find the assembly I noted for that upload and then populate the meta data about the upload once done.

At the time I posted this, I initially postulated this was possible, but since have built it and its working quite well.



来源:https://stackoverflow.com/questions/19434968/transloadit-and-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!