如何使用Dropzonejs将照片从Android中的画廊上传到网站? [英] How to upload photo from gallery in Android to a website with Dropzonejs?
问题描述
我正在使用dropzonejs将照片上传到我的网站.问题是,当我单击dropzone上传时,它不会显示图库"作为此图片中的选项:
Im using dropzonejs to upload photos to my website. The problem is, when I click dropzone to upload, it won't show 'Gallery' as an option as seen in this image :
如何添加图库"作为选项?
How to add Gallery as an option?
推荐答案
事实上,为了向Android用户显示图库应用,您的< input>
元素必须具有两个明确定义的属性:
As a matter of fact, in order to show the gallery app to android user, your <input>
element must have two properties explicitly defined:
类型是文件
,而 accept 可以是 image/*
(或任何其他类型)图像相关的mime类型)
type which is file
and accept which could be, as mentioned, image/*
(or any image-related mime-type)
一种实现此目的的方法是自己实例化Dropzone对象,而不是依赖< form>
的dropzone类:
A way to achieve this is by instantiating the Dropzone object yourself rather than relying on the dropzone class of a <form>
:
// removes the magical auto discovery of dropzone forms
Dropzone.autoDiscover=false;
// add accepted mimeTypes options (comma separated string)
// myDz is the camelCased version of the id of the element that will be "dropzoned"
Dropzone.options.myDz = { acceptedFiles: 'image/*'};
$(function(){
// instantiate dropzone on element with #my-dz id
// if no action in the form or applying dropzone on a non form (ie a div),
// you should at least pass the url in an object as the second parameter
dz = new Dropzone('#my-dz' /*, {url:"/my-upload-url"}*/);
});
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.0.1/dropzone.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.0.1/dropzone.css" rel="stylesheet"/>
</head>
<body>
<div class="ctn">
<h1>Test Dropzone Android</h1>
<form action="#" method="post" class="dropzone" id="my-dz"></form>
</div>
</body>
</html>
您可以在此处找到一些有用(尽管有些过时)的信息:从移动网络应用程序上传照片
You could find some useful (although a little dated) information here: Uploading photos from mobile web app
PS:感谢 John 帮助我收集了这些信息
PS: Thanks to John who helped me to gather those informations
这篇关于如何使用Dropzonejs将照片从Android中的画廊上传到网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!