是否可以将 PLUpload 与 CouchDB 结合使用?

发布于 2024-12-01 03:55:31 字数 106 浏览 2 评论 0原文

我正在寻找将图像上传到我的 CouchDB 并在上传之前调整它们大小的可能性,只要它们仍在客户端中即可。 PLUpload 提供了这样做的可能性,但我想知道是否可以将它与 CouchDB 一起使用。

I am looking for some possibility of uploading images to my CouchDB and resizing them before the upload as long as they are still with the client. PLUpload offers a possibility for doing so but I wonder if it possible to use it together with CouchDB.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

耀眼的星火 2024-12-08 03:55:31

经过大量尝试和阅读,我终于成功使用 PLUpload 将图片上传到 CouchDB。
主要问题是有一个未记录的属性“file_data_name”,必须手动设置该属性才能满足 CouchDB 的需求。默认值为“name”,但 CouchDB 需要“_attachments”。我只是通过检查 Flash 运行时的源代码才发现该属性。

下面是我用来初始化 PLUpload 的 javascript:

$("form#pluploadForm #uploader").plupload({
  // General settings
  runtimes : 'flash,silverlight,html5',
  url : 'http://your.path.to.couchdb.com/database/[documentid]',
  max_file_size : '10mb',
  unique_names : true,
  file_data_name : "_attachments",

  // Resize images on clientside if we can
  resize : {width : 320, height : 240, quality : 90},

  // Specify what files to browse for
  filters : [
    {title : "Image files", extensions : "jpg,gif,png"},
    {title : "Zip files", extensions : "zip"}
  ],

  // Flash settings
  flash_swf_url : 'js/plupload.flash.swf',

  // Silverlight settings
  silverlight_xap_url : 'js/plupload.silverlight.xap',

  multipart : true,
  multipart_params : {
    description: "uploadedViaPlupload",
   _rev: "[the current revision of your document]",
  }
});

但是使用这种方法只能将一张图像发送到一个文档。上传到多个文档不起作用,但我还没有真正尝试过。

After a lot of trying and reading I finally managed to upload a picture to CouchDB using PLUpload.
The main problem was that there is an undocumented property "file_data_name" which has to be set manually to fit with the needs from CouchDB. The default value is "name" but CouchDB is expecting "_attachments". I only found that property by inspecting the source code for the flash runtime.

Below there is the javascript I used for initializing the PLUpload:

$("form#pluploadForm #uploader").plupload({
  // General settings
  runtimes : 'flash,silverlight,html5',
  url : 'http://your.path.to.couchdb.com/database/[documentid]',
  max_file_size : '10mb',
  unique_names : true,
  file_data_name : "_attachments",

  // Resize images on clientside if we can
  resize : {width : 320, height : 240, quality : 90},

  // Specify what files to browse for
  filters : [
    {title : "Image files", extensions : "jpg,gif,png"},
    {title : "Zip files", extensions : "zip"}
  ],

  // Flash settings
  flash_swf_url : 'js/plupload.flash.swf',

  // Silverlight settings
  silverlight_xap_url : 'js/plupload.silverlight.xap',

  multipart : true,
  multipart_params : {
    description: "uploadedViaPlupload",
   _rev: "[the current revision of your document]",
  }
});

But with this approach it is only possible to one image to one single document. Uploading to multiple documents isn't working but I didn't really try it (yet).

想挽留 2024-12-08 03:55:31

您想要做的是覆盖 PLUploader 的 BeforeUpload 事件,以便在上传文件之前使用您的 couch 实例。在下面的方法中,我创建一个新文档(使用 jquery.couch.js),获取响应并使用新文档的新 _id 和 _rev 来设置 PLUploader 实例选项。

uploader.bind('BeforeUpload', function(up, file) {
  $db.saveDoc({
    users : ['all']
  }, {
    success : function(response) {
      if(response.ok) {
        up.settings.url = 'http://127.0.0.1:5984/filesystem/' + response.id;
        up.settings.multipart_params._rev = response.rev;
        up.trigger("UploadFile", file);
      }
    }
  });
  return false;
});

What you want to do is override the BeforeUpload event of PLUploader to work with your couch instance before uploading the file. In the method below, I am creating a new document (using jquery.couch.js), getting the response and using the new _id and _rev of the new document to set the PLUploader instance options.

uploader.bind('BeforeUpload', function(up, file) {
  $db.saveDoc({
    users : ['all']
  }, {
    success : function(response) {
      if(response.ok) {
        up.settings.url = 'http://127.0.0.1:5984/filesystem/' + response.id;
        up.settings.multipart_params._rev = response.rev;
        up.trigger("UploadFile", file);
      }
    }
  });
  return false;
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文