[英]Uploading to Google Drive - how to use a base64-encoded image or an image path
Fairly new to Javascript and still running into this problem after trying a lot of things: 对Javascript来说还很陌生,在尝试了很多尝试之后仍然遇到了这个问题:
I'm using http://ngcordova.com/docs/plugins/camera/ to capture an image on the phone and can retrieve as either a base64-encoded image or as a path to the image location (file://storage/emulated/...jpg). 我正在使用http://ngcordova.com/docs/plugins/camera/在手机上捕获图像,并且可以将其检索为base64编码的图像或图像位置的路径(file:// storage /仿真/...jpg)。
Next I'm using this to upload files to google drive: https://github.com/googledrive/cors-upload-sample 接下来,我正在使用此文件将文件上传到Google驱动器: https : //github.com/googledrive/cors-upload-sample
I've successfully uploaded a text file with the given example: 我已成功上传带有给定示例的文本文件:
* @example
* var content = new Blob(["Hello world"], {"type": "text/plain"});
* var uploader = new MediaUploader({
* file: content,
* token: accessToken,
* onComplete: function(data) { ... }
* onError: function(data) { ... }
* });
* uploader.upload();
But when I upload an image, it cannot be viewed and I assume it is because I have encoded it wrong. 但是,当我上传图像时,无法查看它,我认为这是因为我将其编码错误。
Here's what I've tried so far: 到目前为止,这是我尝试过的方法:
Is it also possible to use a FileReader to read the image path into a File instead? 是否还可以使用FileReader代替将图像路径读取到File中? I just can't figure out what exactly should go into the "file: content" part for an image for the above example code.
对于上述示例代码,我只是无法弄清楚图像的“文件:内容”部分到底应该输入什么。
Any help would be greatly appreciated! 任何帮助将不胜感激!
The upload is expecting the raw image bytes. 上载需要原始图像字节。
Haven't tried this, but easiest approach is likely working with the image URL which you can resolve to a file (which is also a blob :) 尚未尝试过,但是最简单的方法可能是处理图像URL,您可以将其解析为文件(也是blob :)
Something like: 就像是:
window.resolveLocalFileSystemURL(uri, function(fileEntry) { var errorHandler = ...; fileEntry.file(function(file) { var uploader = new MediaUploader({ file: file, token: accessToken, onComplete: function(data) { ... } onError: function(data) { ... } }); uploader.upload(); }, errorHandler); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.