简体   繁体   English

将content://文件上传到服务器

[英]Upload content:// file to server

I have uri of file on android phone : content://com.android.contacts/contacts/472/photo . 我在android手机上有uri文件: content://com.android.contacts/contacts/472/photo I got it from PhoneGap Contacts plugin. 我是从PhoneGap Contacts插件获得的。 It is actually contact image. 它实际上是联系人图像。 Now I need to upload that image on server but when I upload it and try to see it it is not visible. 现在,我需要将该图像上传到服务器上,但是当我上传它并尝试查看它时,它不可见。 I managed to google a little bit and found that for file upload I need to have full file:// path. 我设法用Google搜索了一下,发现要上传文件,我需要完整的file://路径。 Now my question is how to convert content:// to file:// or how to upload files with content:// uri on server? 现在我的问题是如何将content://转换为file://或如何在服务器上上传带有content:// uri的文件?

I have tried using window.resolveLocalFileSystemURI(uri, win, fail); 我已经尝试使用window.resolveLocalFileSystemURI(uri, win, fail); and than 然后

function win(fe){
    alert("win");
    alert(fe.fullPath);
}
function fail(a){
    alert('fail');
}

But somehow it just "skipp" window.resolveLocalFileSystemURI(uri, win, fail); 但是不知何故,它只是“跳过” window.resolveLocalFileSystemURI(uri, win, fail); . It is never executed... No error in LogCat and no any alert from these 3 ... Can this be solution of my problem and why no response is returned? 它永远不会执行... LogCat中没有错误,并且这3个都没有任何警报...这可以解决我的问题,为什么不返回响应?

I don't have direct experience with the contacts plugin, but the docs make me think that you are not looking at a filesystem URI, rather an entry in the contacts database. 我没有使用contacts插件的直接经验,但是文档使我认为您不是在查看文件系统URI,而是在contacts数据库中的条目。 [http://docs.phonegap.com/en/3.3.0/cordova_contacts_contacts.md.html#contacts.find] [http://docs.phonegap.com/en/3.3.0/cordova_contacts_contacts.md.html#contacts.find]

So, you are likely mis-interpreting the concept of a URI, especially in the context of the filesystem. 因此,您可能会误解URI的概念,尤其是在文件系统的上下文中。 [http://en.wikipedia.org/wiki/Uniform_resource_identifier] and [http://www.html5rocks.com/en/tutorials/file/filesystem/]. [http://en.wikipedia.org/wiki/Uniform_resource_identifier]和[http://www.html5rocks.com/zh-CN/tutorials/file/filesystem/]。

From the plugin docs, we do see that 'photos' is a property of each contact. 从插件文档中,我们确实看到“照片”是每个联系人的属性。

how to upload files with content:// uri on server? 如何在服务器上上传带有content:// uri的文件?

for the desired contact, you could create a file using the photos property, and then upload using the phonegap file-transfer plugin. 对于所需的联系人,您可以使用photos属性创建一个文件,然后使用phonegap文件传输插件上传。 [http://docs.phonegap.com/en/3.3.0/cordova_file_file.md.html#FileTransfer] [http://docs.phonegap.com/en/3.3.0/cordova_file_file.md.html#FileTransfer]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM