简体   繁体   English

Filepicker? 通过HTML5将大文件上传到S3,没有后端

[英]Filepicker? Upload big files via HTML5 to S3 with no backend

Upload files with multipart/form-data is straight forward and works well most of time until you started to be focused on big files upload. 使用multipart / form-data上传文件很简单,大部分时间都可以正常工作,直到您开始专注于大文件上传。 If we look closely what happens during a file upload: 如果我们仔细查看文件上传期间发生的情况:

  • client sends POST request with the file content in BODY 客户端发送带有BODY文件内容的POST请求

  • webserver accepts the request and initiates data transfer (or returns error 413 if the file size is exceed the limit) webserver接受请求并启动数据传输(如果文件大小超过限制,则返回错误413)

  • webserver starts to populate buffers (depends on file and buffers size), store it on disk and send it via socket/network to back-end webserver开始填充缓冲区(取决于文件和缓冲区大小),将其存储在磁盘上并通过套接字/网络发送到后端

  • back-end verifies the authentication (take a look, once file is uploaded) 后端验证身份验证(看一下文件上传后)

  • back-end reads the file and cuts few headers Content-Disposition, Content-Type, stores it on disk again back-end performs all you need to do with the file 后端读取文件并删除少量标题Content-Disposition,Content-Type,将其再次存储在磁盘上后端执行文件所需的全部操作

To avoid such overhead we dump file on disk (Nginx client_body_in_file_only) and manage the callback to be send further down the line. 为了避免这种开销,我们将文件转储到磁盘上(Nginx client_body_in_file_only)并管理回调以便进一步向下发送。 Then queue worker picks the file up and do what required. 然后队列工作者选择文件并执行所需操作。 It works for inter-server communication pretty slick but we have to solve similar problem with client side upload. 它适用于服务器间通信非常流畅,但我们必须解决客户端上传的类似问题。

We also have client-side S3 upload solution. 我们还有客户端S3上传解决方案。 No back-end interaction happens. 没有后端交互发生。 For video upload we manage the video to convert to the format h.264 Baseline / AAC with Zencoder. 对于视频上传,我们管理视频以转换为带有Zencoder的h.264 Baseline / AAC格式。

Currently we use modified Flash uploader based on s3-swf-upload-plugin with combination of Zencoder JS SDK which is really efficient but uses Flash. 目前我们使用基于s3-swf-upload-plugin的改进的Flash上​​传器与Zencoder JS SDK的组合,该SDK非常高效但使用Flash。

Question. 题。 How to reach the same goal with HTML5 file uploader? 如何使用HTML5文件上传器达到相同的目标? Does Filepicker.io and Zencoder solve the problem? Filepicker.io和Zencoder是否解决了这个问题? What is the recommended way to manage HTML5 file upload with no back-end interaction? 在没有后端交互的情况下管理HTML5文件上传的推荐方法是什么?

The requirements are the following: 要求如下:

  • HTML5, not flash HTML5,而不是flash
  • to upload video with post-processing to make it compatible with HTML5 players and mobile 通过后期处理上传视频,使其与HTML5播放器和移动设备兼容
  • to upload images wtih post-processing (resize, crop, rotate) 通过后期处理上传图像(调整大小,裁剪,旋转)
  • to upload documents like PDF with a preview functionality 使用预览功能上传PDF等文档

Does https://www.filepicker.com make a good job? https://www.filepicker.com做得好吗?

I'm using filepicker for 2 years now, and without doubt it's worth the price. 我现在使用filepicker已有2年了,毫无疑问,这是物有所值的。 don't try to manage file upload (from google drive, from ios, from my camera, from dropbox...) Filepicker handles that very well and provide you a ready to use url. 不要尝试管理文件上传(从谷歌驱动器,从ios,从我的相机,从Dropbox ...)Filepicker处理得很好,并为您提供随时可用的网址。 Spend more time working on your core business, file upload is really easy to delegate 花更多时间在您的核心业务上工作,文件上传非常容易委派

The requirements are the following: 要求如下:

HTML5, not flash HTML5,而不是flash

Filepicker now supports a full responsive widget that is pure html and css. Filepicker现在支持完整的响应小部件,它是纯html和css。

to upload video with post-processing to make it compatible with HTML5 players and mobile 通过后期处理上传视频,使其与HTML5播放器和移动设备兼容

Filepicker now offers the ability to transcode most video formats to h264 & webm for mobile playback. Filepicker现在能够将大多数视频格式转码为h264和webm以进行移动播放。 https://www.filepicker.com/documentation/file_processing/video_conversion/video https://www.filepicker.com/documentation/file_processing/video_conversion/video

to upload images wtih post-processing (resize, crop, rotate) 通过后期处理上传图像(调整大小,裁剪,旋转)

Filepicker does offer Crop & rotate in the new widget as well as resize, sharpening and watermarking via API. Filepicker确实提供了新窗口小部件中的裁剪和旋转,以及通过API调整大小,锐化和水印。

to upload documents like PDF with a preview functionality 使用预览功能上传PDF等文档

We offer the ability to convert from 19 different file formats to numerous output formats. 我们提供从19种不同文件格式转换为多种输出格式的功能。 https://www.filepicker.com/documentation/file_processing/document_conversion/document https://www.filepicker.com/documentation/file_processing/document_conversion/document

To upload a big files to S3 there is a REST API for Multipart Upload , which works the following way 要将大文件上传到S3,有一个用于分段上传REST API ,它按以下方式工作

  1. initiate an upload 发起上传
  2. upload file content split into multiple requests 上传文件内容分为多个请求
  3. finish the upload 完成上传

the API is also available for calling from javascript and the uploaded file can be split to multiple requests using File/Blob slice API API也可用于从javascript调用,并且可以使用File / Blob slice API将上传的文件拆分为多个请求

The only problem is that to be able to authenticate to S3 from javascript you need to pass your authentication details. 唯一的问题是,要能够通过javascript对S3进行身份验证,您需要传递身份验证详细信息。 This is usually solved by some interlayer like PHP so the authentication details are not stored in javascript files. 这通常通过像PHP这样的夹层来解决,因此身份验证详细信息不会存储在javascript文件中。

Similar question on SO: HTML5 and Amazon S3 Multi-Part uploads 关于SO的类似问题: HTML5和Amazon S3多部分上传

EDIT 编辑

  • image operations like cropping and resizing can be done by canvas. 裁剪和调整大小等图像操作可以通过画布完成。 Just load the local image into the canvas element, make the edits you need and then you can generate jpeg/png image data stream using canvas.toDataUrl method. 只需将本地图像加载到canvas元素中,进行所需的编辑,然后使用canvas.toDataUrl方法生成jpeg / png图像数据流。
  • PDF preview is possible, there is a PDF.js lib that can render local PDF file into the canvas 可以进行PDF预览,有一个PDF.js lib可以将本地PDF文件渲染到画布中
  • AFAIK there is no way to do video conversion on the client side AFAIK无法在客户端进行视频转换

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

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