简体   繁体   English

Plupload:如何直接从相机上传(在移动设备上)

[英]Plupload: How to upload directly from a camera (on mobile devices)

I'm using Plupload to let users upload images to my WordPress website. 我正在使用Plupload让用户将图像上传到我的WordPress网站。

When a user clicks on 'Select files' and chooses an image from their mobile phone's gallery, the image's filename appears on screen. 当用户点击“选择文件”并从手机图库中选择图像时,图像的文件名将显示在屏幕上。 The user is then free to click on 'Upload files' to start the upload. 然后,用户可以自由点击“上传文件”以开始上传。

My problem 我的问题

When a user clicks on 'Select files' and takes a photo with their camera phone, the image's filename doesn't appear on screen. 当用户点击“选择文件”并使用他们的照相手机拍照时,图像的文件名不会出现在屏幕上。 In this case, when the user now tries clicking on 'Upload files', nothing happens. 在这种情况下,当用户现在尝试单击“上载文件”时,没有任何反应。 How can I resolve this? 我该如何解决这个问题?

Notes 笔记

The problem doesn't happen at all when I use my tablet or desktop. 当我使用平板电脑或台式机时,问题根本不会发生。

Update 更新

My testing was done using two mobile devices: 我的测试是使用两个移动设备完成的:

  1. Chrome on a Samsung Galaxy S4 Mini running Android 4.2.2 运行Android 4.2.2的三星Galaxy S4 Mini上的Chrome
  2. Chrome on a Samsung Galaxy Ace II running Android 4.1.2 运行Android 4.1.2的三星Galaxy Ace II上的Chrome

Here's a demo of the code I'm using: http://jsfiddle.net/djydce90/ 这是我正在使用的代码的演示: http//jsfiddle.net/djydce90/

My script 我的剧本

var uploader = new plupload.Uploader({
  runtimes : 'html5,flash,silverlight,html4',
  browse_button : 'pickfiles',
  container: document.getElementById( 'container' ),
  url : "/examples/upload",
  filters : {
    max_file_size : '10mb',
    mime_types: [
      {title : "Image files", extensions : "jpg,gif,png"},
      {title : "Zip files", extensions : "zip"}
    ]
  },
  flash_swf_url : '/plupload/js/Moxie.swf',
  silverlight_xap_url : '/plupload/js/Moxie.xap',
  init: {
    PostInit: function() {
      document.getElementById('filelist').innerHTML = '';

      document.getElementById('uploadfiles').onclick = function() {
        uploader.start();
        return false;
      };
    },
    FilesAdded: function(up, files) {
      plupload.each(files, function(file) {
        document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
      });
    },
    UploadProgress: function(up, file) {
      document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
    },
    Error: function(up, err) {
      document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
    }
  }
});

uploader.init();

My HTML 我的HTML

<script src="https://rawgit.com/moxiecode/plupload/master/js/plupload.full.min.js"></script>
<div id="filelist">Your browser doesn't have Flash, Silverlight or HTML5 support.</div>
<br />
<div id="container">
  <a id="pickfiles" href="javascript:;">[Select files]</a>
  <a id="uploadfiles" href="javascript:;">[Upload files]</a>
</div>

Ref: http://www.plupload.com/examples/core 参考: http //www.plupload.com/examples/core

The problem comes from method of capturing images.Android gives you a bitmap object when you take a pic,so you need to upload that bitmap instead of a file.When you select a file from your memory it sends you that path but in capturing you give that photo data in details . 问题来自于捕获图像的方法。当您拍摄照片时,Android会为您提供位图对象,因此您需要上传该位图而不是文件。当您从内存中选择一个文件时,它会向您发送该路径但是会捕获您详细提供照片数据。 so you need to upload that photo data instead of uploading a file.I don't know exactly can pluplaoad handle this or no but you can go through this link to get a sight of it. 所以你需要上传那些照片数据而不是上传文件。我不知道pluplaoad可以处理这个或没有,但你可以通过这个链接来看到它。

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

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