Giter Club home page Giter Club logo

uploader's Introduction

simple-uploader.js Build Status codecov.io Build Status

Sauce Test Status

中文

QQ

A JavaScript library providing multiple simultaneous, stable, fault-tolerant and resumable/restartable file uploads via the HTML5 File API.

Forked flow.js but refactor it.

The library is designed to introduce fault-tolerance into the upload of large files through HTTP. This is done by splitting each file into small chunks. Then, whenever the upload of a chunk fails, uploading is retried until the procedure completes. This allows uploads to automatically resume uploading after a network connection is lost either locally or to the server. Additionally, it allows for users to pause, resume and even recover uploads without losing state because only the currently uploading chunks will be aborted, not the entire upload.

Uploader (simple-uploader.js) does not have any external dependencies other than the HTML5 File API. This is relied on for the ability to chunk files into smaller pieces. Currently, this means that support is limited to Firefox 4+, Chrome 11+, Safari 6+ and Internet Explorer 10+.

Samples and examples are available in the samples/ folder. Please push your own as Markdown to help document the project.

New Features

  • Treat Folder and File as Uploader.File

  • Treat Uploader as a root Folder

  • New fileList property which contains files and folders

How can I install it?

Download a latest build from https://github.com/simple-uploader/Uploader/releases/ it contains development and minified production files in dist/ folder.

or use npm:

npm install simple-uploader.js

or use git clone

git clone https://github.com/simple-uploader/Uploader

How can I use it?

A new Uploader object is created with information of what and where to post:

var uploader = new Uploader({
  target: '/api/photo/redeem-upload-token', 
  query: { upload_token: 'my_token' }
})
// Uploader isn't supported, fall back on a different method
if (!uploader.support) location.href = '/some-old-crappy-uploader'

To allow files to be either selected and drag-dropped, you'll assign drop target and a DOM item to be clicked for browsing:

uploader.assignBrowse(document.getElementById('browseButton'))
uploader.assignDrop(document.getElementById('dropTarget'))

After this, interaction with Uploader.js is done by listening to events:

uploader.on('fileAdded', function (file, event) {
  console.log(file, event)
})
uploader.on('fileSuccess', function (rootFile, file, message) {
  console.log(rootFile, file, message)
})
uploader.on('fileComplete', function (rootFile) {
  console.log(rootFile)
})
uploader.on('fileError', function (rootFile, file, message) {
  console.log(rootFile, file, message)
})

How do I set it up with my server?

Most of the magic for Uploader.js happens in the user's browser, but files still need to be reassembled from chunks on the server side. This should be a fairly simple task and can be achieved in any web framework or language, which is able to receive file uploads.

To handle the state of upload chunks, a number of extra parameters are sent along with all requests:

  • chunkNumber: The index of the chunk in the current upload. First chunk is 1 (no base-0 counting here).
  • totalChunks: The total number of chunks.
  • chunkSize: The general chunk size. Using this value and totalSize you can calculate the total number of chunks. Please note that the size of the data received in the HTTP might be greater than chunkSize of this for the last chunk for a file.
  • totalSize: The total file size.
  • identifier: A unique identifier for the file contained in the request.
  • filename: The original file name (since a bug in Firefox results in the file name not being transmitted in chunk multipart posts).
  • relativePath: The file's relative path when selecting a directory (defaults to file name in all browsers except Chrome).

You should allow for the same chunk to be uploaded more than once; this isn't standard behaviour, but on an unstable network environment it could happen, and this case is exactly what Uploader.js is designed for.

For every request, you can confirm reception in HTTP status codes (can be change through the permanentErrors option):

  • 200, 201, 202: The chunk was accepted and correct. No need to re-upload.
  • 404, 415. 500, 501: The file for which the chunk was uploaded is not supported, cancel the entire upload.
  • Anything else: Something went wrong, but try reuploading the file.

Handling GET (or test() requests)

Enabling the testChunks option will allow uploads to be resumed after browser restarts and even across browsers (in theory you could even run the same file upload across multiple tabs or different browsers). The POST data requests listed are required to use Uploader.js to receive data, but you can extend support by implementing a corresponding GET request with the same parameters:

  • If this request returns a 200, 201 or 202 HTTP code, the chunks is assumed to have been completed.
  • If request returns a permanent error status, upload is stopped.
  • If request returns anything else, the chunk will be uploaded in the standard fashion.

After this is done and testChunks enabled, an upload can quickly catch up even after a browser restart by simply verifying already uploaded chunks that do not need to be uploaded again.

Full documentation

Uploader

Configuration

The object is loaded with a configuration options:

var r = new Uploader({ opt1: 'val', ...})

Available configuration options are:

  • target The target URL for the multipart POST request. This can be a string or a function. If a function, it will be passed a Uploader.File, a Uploader.Chunk and isTest boolean (Default: /)
  • singleFile Enable single file upload. Once one file is uploaded, second file will overtake existing one, first one will be canceled. (Default: false)
  • chunkSize The size in bytes of each uploaded chunk of data. The last uploaded chunk will be at least this size and up to two the size, see Issue #51 for details and reasons. (Default: 1*1024*1024)
  • forceChunkSize Force all chunks to be less or equal than chunkSize. Otherwise, the last chunk will be greater than or equal to chunkSize. (Default: false)
  • simultaneousUploads Number of simultaneous uploads (Default: 3)
  • fileParameterName The name of the multipart POST parameter to use for the file chunk (Default: file)
  • query Extra parameters to include in the multipart POST with data. This can be an object or a function. If a function, it will be passed a Uploader.File, a Uploader.Chunk object and a isTest boolean (Default: {})
  • headers Extra headers to include in the multipart POST with data. If a function, it will be passed a Uploader.File, a Uploader.Chunk object and a isTest boolean (Default: {})
  • withCredentials Standard CORS requests do not send or set any cookies by default. In order to include cookies as part of the request, you need to set the withCredentials property to true. (Default: false)
  • method Method to use when POSTing chunks to the server (multipart or octet) (Default: multipart)
  • testMethod HTTP method to use when chunks are being tested. If set to a function, it will be passed a Uploader.File and a Uploader.Chunk arguments. (Default: GET)
  • uploadMethod HTTP method to use when chunks are being uploaded. If set to a function, it will be passed a Uploader.File arguments. (Default: POST)
  • allowDuplicateUploads Once a file is uploaded, allow reupload of the same file. By default, if a file is already uploaded, it will be skipped unless the file is removed from the existing Uploader object. (Default: false)
  • prioritizeFirstAndLastChunk Prioritize first and last chunks of all files. This can be handy if you can determine if a file is valid for your service from only the first or last chunk. For example, photo or video meta data is usually located in the first part of a file, making it easy to test support from only the first chunk. (Default: false)
  • testChunks Make a GET request to the server for each chunks to see if it already exists. If implemented on the server-side, this will allow for upload resumes even after a browser crash or even a computer restart. (Default: true)
  • preprocess Optional function to process each chunk before testing & sending. To the function it will be passed the chunk as parameter, and should call the preprocessFinished method on the chunk when finished. (Default: null)
  • initFileFn Optional function to initialize the fileObject. To the function it will be passed a Uploader.File arguments.
  • readFileFn Optional function wrapping reading operation from the original file. To the function it will be passed the Uploader.File, the startByte and endByte, the fileType and the Uploader.Chunk. And should call the readFinished method with bytes arguments on the chunk when finished.
  • checkChunkUploadedByResponse Optional function to check chunk was uploaded by XHR response. To the function it will be passed the Uploader.Chunk and the response message. You do not need to upload(test) all chunks now, see Issue #1 for details and reasons, sample.
  • generateUniqueIdentifier Override the function that generates unique identifiers for each file. (Default: null)
  • maxChunkRetries The maximum number of retries for a chunk before the upload is failed. Valid values are any positive integer and undefined for no limit. (Default: 0)
  • chunkRetryInterval The number of milliseconds to wait before retrying a chunk on a non-permanent error. Valid values are any positive integer and undefined for immediate retry. (Default: undefined)
  • progressCallbacksInterval The time interval in milliseconds between progress reports. Set it to 0 to handle each progress callback. (Default: 500)
  • speedSmoothingFactor Used for calculating average upload speed. Number from 1 to 0. Set to 1 and average upload speed wil be equal to current upload speed. For longer file uploads it is better set this number to 0.02, because time remaining estimation will be more accurate. This parameter must be adjusted together with progressCallbacksInterval parameter. (Default 0.1)
  • successStatuses Response is success if response status is in this list (Default: [200,201, 202])
  • permanentErrors Response fails if response status is in this list (Default: [404, 415, 500, 501])
  • initialPaused Initial paused state, default false.
  • processResponse Process xhr response, default function (response, cb) { cb(null, response) }. After 0.5.2, processResponse will be called with arguments: (response, cb, Uploader.File, Uploader.Chunk).
  • processParams Process xhr params, default function (params) {return params}. After 0.5.2, processParams will be called with arguments: (params, Uploader.File, Uploader.Chunk, isTest).

Properties

  • .support A boolean value indicator whether or not Uploader.js is supported by the current browser.
  • .supportDirectory A boolean value, which indicates if browser supports directory uploads.
  • .opts A hash object of the configuration of the Uploader.js instance.
  • .files An array of Uploader.File file objects added by the user (see full docs for this object type below).
  • .fileList An array of Uploader.File file(folder) objects added by the user (see full docs for this object type below), but it treated Folder as a Uploader.File Object.

Methods

  • .assignBrowse(domNodes, isDirectory, singleFile, attributes) Assign a browse action to one or more DOM nodes.

    • domNodes array of dom nodes or a single node.
    • isDirectory Pass in true to allow directories to be selected (Chrome only, support can be checked with supportDirectory property).
    • singleFile To prevent multiple file uploads set this to true. Also look at config parameter singleFile.
    • attributes Pass object of keys and values to set custom attributes on input fields. For example, you can set accept attribute to image/*. This means that user will be able to select only images. Full list of attributes: https://www.w3.org/wiki/HTML/Elements/input/file

    Note: avoid using a and button tags as file upload buttons, use span instead.

  • .assignDrop(domNodes) Assign one or more DOM nodes as a drop target.

  • .unAssignDrop(domNodes) Unassign one or more DOM nodes as a drop target.

  • .on(event, callback) Listen for event from Uploader.js (see below)

  • .off([event, [callback]]):

    • .off(event) Remove all callbacks of specific event.
    • .off(event, callback) Remove specific callback of event. callback should be a Function.
  • .upload() Start or resume uploading.

  • .pause() Pause uploading.

  • .resume() Resume uploading.

  • .cancel() Cancel upload of all Uploader.File objects and remove them from the list.

  • .progress() Returns a float between 0 and 1 indicating the current upload progress of all files.

  • .isUploading() Returns a boolean indicating whether or not the instance is currently uploading anything.

  • .addFile(file) Add a HTML5 File object to the list of files.

  • .removeFile(file) Cancel upload of a specific Uploader.File object on the list from the list.

  • .getFromUniqueIdentifier(uniqueIdentifier) Look up a Uploader.File object by its unique identifier.

  • .getSize() Returns the total size of the upload in bytes.

  • .sizeUploaded() Returns the total size uploaded of all files in bytes.

  • .timeRemaining() Returns remaining time to upload all files in seconds. Accuracy is based on average speed. If speed is zero, time remaining will be equal to positive infinity Number.POSITIVE_INFINITY

Events

  • .change(event) File input change event.
  • .dragover(event) Drop area dragover event.
  • .dragenter(event) Drop area dragenter event.
  • .dragleave(event) Drop area dragleave event.
  • .fileSuccess(rootFile, file, message, chunk) A specific file was completed. First argument rootFile is the root Uploader.File instance which contains or equal the completed file, second argument file argument is instance of Uploader.File too, it's the current completed file object, third argument message contains server response. Response is always a string. Fourth argument chunk is instance of Uploader.Chunk. You can get response status by accessing xhr object chunk.xhr.status.
  • .fileComplete(rootFile) A root file(Folder) was completed.
  • .fileProgress(rootFile, file, chunk) Uploading progressed for a specific file.
  • .fileAdded(file, event) This event is used for file validation. To reject this file return false. This event is also called before file is added to upload queue, this means that calling uploader.upload() function will not start current file upload. Optionally, you can use the browser event object from when the file was added.
  • .filesAdded(files, fileList, event) Same as fileAdded, but used for multiple file validation.
  • .filesSubmitted(files, fileList, event) Same as filesAdded, but happens after the file is added to upload queue. Can be used to start upload of currently added files.
  • .fileRemoved(file) The specific file was removed from the upload queue. Combined with filesSubmitted, can be used to notify UI to update its state to match the upload queue.
  • .fileRetry(rootFile, file, chunk) Something went wrong during upload of a specific file, uploading is being retried.
  • .fileError(rootFile, file, message, chunk) An error occurred during upload of a specific file.
  • .uploadStart() Upload has been started.
  • .complete() Uploading completed.
  • .catchAll(event, ...) Listen to all the events listed above with the same callback function.

Uploader.File

Properties

  • .uploader A back-reference to the parent Uploader object.
  • .name The name of the file(folder).
  • .averageSpeed Average upload speed, bytes per second.
  • .currentSpeed Current upload speed, bytes per second.
  • .paused Indicated if file(folder) is paused.
  • .error Indicated if file(folder) has encountered an error.
  • .isFolder Indicated if file(folder) is an Directory.

If .isFolder is false then these properties will be added:

  • .file The correlating HTML5 File object.
  • .relativePath The relative path to the file (defaults to file name if relative path doesn't exist).
  • .size Size in bytes of the file.
  • .uniqueIdentifier A unique identifier assigned to this file object. This value is included in uploads to the server for reference, but can also be used in CSS classes etc when building your upload UI.
  • .chunks An array of Uploader.Chunk items. You shouldn't need to dig into these.

Methods

  • .getRoot() Returns the file's root Uploader.File instance in uploader.fileList.
  • .progress() Returns a float between 0 and 1 indicating the current upload progress of the file.
  • .pause() Pause uploading the file.
  • .resume() Resume uploading the file.
  • .cancel() Abort uploading the file and delete it from the list of files to upload.
  • .retry() Retry uploading the file.
  • .bootstrap() Rebuild the state of a Uploader.File object, including reassigning chunks and XMLHttpRequest instances.
  • .isUploading() Returns a boolean indicating whether file chunks is uploading.
  • .isComplete() Returns a boolean indicating whether the file has completed uploading and received a server response.
  • .sizeUploaded() Returns size uploaded in bytes.
  • .timeRemaining() Returns remaining time to finish upload file in seconds. Accuracy is based on average speed. If speed is zero, time remaining will be equal to positive infinity Number.POSITIVE_INFINITY
  • .getExtension() Returns file extension in lowercase.
  • .getType() Returns file type.

Origin

Uploader.js was inspired by and evolved from https://github.com/flowjs/flow.js and https://github.com/23/resumable.js.

uploader's People

Contributors

dependabot[bot] avatar dolymood avatar gntyu avatar lubanproj avatar mche avatar mrcare avatar msidolphin avatar wxy8855723 avatar xluo127 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uploader's Issues

遇到安卓不支持定义多项accept的问题

这是某些安卓手机的问题,和代码无关。在这里只是想求个帮助。
不知道作者有没有比较好的解决方案,天天为了去适配这些破安卓手机,无语了。

    attrs () {
      return {        
        accept: 'video/*,image/*',        
      }
    },

可以看到生成了:

<input type="file" accept="video/*,image/*" style="visibility: hidden; position: absolute; width: 1px; height: 1px;">

但有的安卓手机只识别到第一个,例如:video/* ,忽略了后面的
点开选择文件的时候 只有视频文件,图片的被过滤掉了。

计算MD5过程中,再次选择该文件,会添加失败。

您好:
在添加文件中加入了计算MD5过程。但是计算MD5过程中,再次选择该文件,会添加失败(没反应)。在计算MD5结束(还在上传中)就可以再次添加该文件。对此状况,您有什么建议吗?非常感谢

如何在上传之前做表单验证

在文件上传时需要附带query信息,其中部分是必须的值,因此需要在点击上传文件时做表单验证。
目前的问题是,在哪里写验证方法?

怎么上传相同文件啊?

选择完文件上传后,当我再次选择相同文件时会触发change事件,但是fileList不会变?请教。。

大文件秒传需求建议

可否增加一个事件:每个文件在上传之前可以触发,根据服务端内容判断文件是否需要上传,因为有的文件服务端已经存在,不需要再上传。这个时间不是针对chunk的,是针对文件的,场景如下:比如,用户选择了5个文件A、B、C、D、E,每个文件3G,实际上服务端已经有C和D两个文件。文件开始上传,A、B,传到C的时候,事件触发,服务端返回数据告诉文件已经存在,不需要传了,然后调用方法,在用户界面显示C已经传完。让后继续传D,触发事件,不需要传,然后再继续传E,服务端没有这个文件,需要传。因为文件秒传不仅仅是chunk需要,针对整个文件也需要。本身我是做后端的,也许你们已经有这个机制,只是我没找到,有的话麻烦告诉下。另外说一下,这个上传插件确实很给力,我们这里用来传大文件,动不动就是几个G。

上传文件报错

Uncaught TypeError: this.xhr.upload.addEventListener is not a function
at Chunk.send (chunk.js?293b:147)
at Chunk.readFinished (chunk.js?293b:112)
at webAPIFileRead (uploader.js?1e8e:68)
at Chunk.send (chunk.js?293b:131)
at eval (uploader.js?1e8e:253)
at Object.each (utils.js?bd76:63)
at eval (uploader.js?1e8e:251)
at Object.each (utils.js?bd76:63)
at Uploader.uploadNextChunk (uploader.js?1e8e:245)
at Uploader.upload (uploader.js?1e8e:294)

怎么改变或者获知文件的上传状态。

我的需求是这样的,文件上传到服务器之后还要进行处理,只有处理完才能算上传完。所以进度条100%时我想显示文件处理中...提示用户文件还没上传完。通过file-progress事件,发现没有一个表示现在具体进度或者状态的字段,问下这个改怎么处理,谢谢。

如何取消分块上传

目前解决方法是 chunkSize 设置一个足够大的值;
是否考虑增加一个是否开启分块上传的配置

Resumeable Uploads via Content-Range

First of all, great project!

I'd like to be able to integrate this into my project with my backend (Google Cloud Storage) but the application doesn't support one method of resumable uploads: Content-Range

The GCP docs define how this should be done, by checking to see which bytes have been uploaded and to continue uploading from the next byte forward. The multiple-chunk option from Google is a little weird in that it still expects the file to be uploaded in order and with a single chunk at a time.

I think the project can accommodate this fairly easily by the adding a user setting for resumable upload type - chunk or range, where the range type alters the flow as follows:

  • The upload type should default to octet (or let the user handle this)
  • omit the query/data params about the upload from being added to the request data and query params (this is the only step that I can't find a workaround too)
  • The library should assume a single chunk operation (or let the developer set the chunkSize to the maximum file size they want to support)
  • testChunks should be false (or let the developer set this themselves)
  • Add a hook for determining the start byte of where to start uploading from (or I guess the preprocess function can alter this itself?)
  • Add a Content-Range header on the request indicating the start-end bytes the request is submitting (again, perhaps the preprocess function can add this to the Chunk itself?)

I'm actually migrating from using danialfarid/ng-file-upload in my old AngularJS project to Vue and this (along with your other project) looked to be the closest in feature set required for this.

Post Note:

It seems like this could work as-is but I'll have to test it - it definitely feels hacky though so if it makes sense to add this feature as a more supported option, I'd be happy to give my input on any implementation!

上传错误时响应信息为空

在测试过程中发现,若服务器返回 400、415等错误信息,请求的 response data 为空,无法查看错误信息,不够友好

How i can identify the chunks of of next video are started

i am unable to identify the chunks of of next video all of it seems very confusing when comes to fileSuccess and fileCompleted events they should be fired after each file is completed but it isn't working like that uploader is uploading chunks of both first then firing success and completed events
screenshot from 2018-11-29 21-29-12

求解,是不是姿势不对,选完图片没有上传

我下载了dist里面的uploader.min.js 引入页面,然后如下配置,选完图片 然后就没其他动作了,也没看到上传。咱们这个不是自动上传的吗?

var uploader = new Uploader({
            target: CONFIG.back + '/uploadFileBlock',
            query: {
                upload_index: ''
            },
            chunkSize:0.5*1024*1024,//2*1024*1024,
            forceChunkSize:true,
            testChunks: false,
            simultaneousUploads:1,
            allowDuplicateUploads: true,
            successStatuses  :[200],
            permanentErrors :[400,401,404, 415, 500, 501],
        })

        uploader.assignBrowse(document.getElementById('J_logoFile'))
        // 文件添加 单个文件
        uploader.on('fileAdded', function (file, event) {
            console.log(file, event)
            uploader.upload()
        })
        // 单个文件上传成功
        uploader.on('fileSuccess', function (rootFile, file, message) {
            console.log(rootFile, file, message)
        })
        // 根下的单个文件(文件夹)上传完成
        uploader.on('fileComplete', function (rootFile) {
            console.log(rootFile)
        })
        // 某个文件上传失败了
        uploader.on('fileError', function (rootFile, file, message) {
            console.log(rootFile, file, message)
        })
        uploader.on('isUploading', function (flag) {
            console.log(flag)
        })

files content type on dir upload

Hi!

When file single upload then Content-Type inside POST-data is correct, okay.

When dir-multifiles upload then files/chunks POST-data have incorrect Content-Type: application/octet-stream

here my sample where content-type (line 43) must be image/jpeg

events not handling

In my case, uploader sent the file, but do not handle events listeners. I use the simplest event listeners on file fileSuccess and catchAll, but they do not work. I am using the npm package and webpack.

import SimpleUploader from "simple-uploader";

let uploader = new SimpleUploader({
    url: "/api/import.php"
});

// it does not work
uploader.on("fileSuccess", function () {
    console.log("fileSuccess")
});
uploader.on("catchAll", function (rootFile, file, message) {
    console.log("catchAll");
});

// it is okay, file will be sent
const import_file_handler = (event) => {
    uploader.upload(event.target.files);
}

关于fileAdded事件,返回false时的处理,以及分片优化方案的建议

1 监听fileAdded事件,如果返回false,文件未加入上传队列(uploader.files),但却加入了uploader.fileList中并在页面显示了出来。
期望:返回了flase,应该表示该文件不是用户需要的文件,不应该加入uploader.fileList。
uploader.js 133行,可修改为:

     var _file = new File(this, file, this)
      _file.uniqueIdentifier = uniqueIdentifier
      var ignored = this._trigger('fileAdded', _file, evt);

      if (ignored) {
        _file.uploaed = 2;
        _files.push(_file)
      }else{
        this.removeFile(_file)
        //alert(_file.name+':格式不正确')
      }

2:进行分片上传时,有时候并不需要每个分片都做一次testChunks。这样对于较大文件,会浪费很多次请求。
建议,可增加一个参数enableOnceCheck。

enableOnceCheck为true时,在文件加入上传队列时,请求一次后台(GET),获取当前文件已经上传的分片位置,并保存到_file对象中。

如_file.uploadeChunk = 10,开始上传时(uploadNextChunk),直接从第11个分片开始POST(并且此时不需要再做分片检测的GET请求)。这种方案对于大文件,可以节省大量的GET检测请求。

enableOnceCheck为false时,默认状态,依旧对每个分片进行GET检测。

请问能否在上传时,单独处理query参数?!

目录上传,如果目录有子目录和文件,在filesSubmitted事件处理子目录的服务器创建,然后文件上传需要加上query参数写入目录的id.可是现在的query是全局的,没办法在文件上传前就把这个query参数修改掉,即使修改了,多文件同时上传的时候,也会造成query参数在其他文件上传的时候被覆盖掉。
能否把query参数写在fileList的每个file里面,上传的时候直接使用每个file自己的query.

processResponse 如何取消文件上传

场景:文件分块上传。
根据后端返回状态码的不同,需要在processResponse 进行处理,例如,返回一个400,那么我需要提示用户,并删除这个出问题的文件(rootfile),但在processResponse 中如何取得对应的rootfile呢?

如果我能知道当前这个状态对应的rootfile 我就能用cacel进行取消上传···

Uploader uploads to S3 only last chunk

I'm trying to use Uploader for uploading to AWS S3.
So uploaderOptions are

{
    target: this.getS3TargetURL,
    headers: {
        'x-amz-grant-full-control': 'id=...',
        'Content-Type': 'binary/octet-stream'
    },
    testChunks: false,
    uploadMethod: 'PUT'
}

Where getS3TargetURL is a function determining URL relying on name of file.
The problem is that files bigger than chunk size are chopped into chunks (and uploaded in parallel, as I understand, in 3 threads by default), but only last chunk remains as a file content at S3.

Please, give instructions how to upload to AWS S3.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.