• uppy实现断点续传


    • 断点续传服务器后台接口:/FileUpload/Upload
    • 前台代码
    <html>
    <head>
        <meta charset="utf-8">
        <title>Uppy</title>
        <!-- 1. Add CSS to `<head>` -->
        <link href="https://transloadit.edgly.net/releases/uppy/v1.5.0/uppy.min.css" rel="stylesheet">
    </head>
    <body>
        <div id="uppy-dashboard-area"></div>
        <!-- 2. Add JS before the closing `</body>` -->
        <script src="https://transloadit.edgly.net/releases/uppy/v1.5.0/uppy.min.js"></script>
        <script>
            var zhcn = {
                strings: {
                    // When `inline: false`, used as the screen reader label for the button that closes the modal.
                    closeModal: '关闭弹框',
                    // Used as the screen reader label for the plus (+) button that shows the “Add more files” screen
                    addMoreFiles: '添加更多文件',
                    // Used as the header for import panels, e.g., “Import from Google Drive”.
                    importFrom: '从 %{name} 导入',
                    // When `inline: false`, used as the screen reader label for the dashboard modal.
                    dashboardWindowTitle: 'Uppy Dashboard Window (Press escape to close)',
                    // When `inline: true`, used as the screen reader label for the dashboard area.
                    dashboardTitle: 'Uppy Dashboard',
                    // Shown in the Informer when a link to a file was copied to the clipboard.
                    copyLinkToClipboardSuccess: '链接已复制',
                    // Used when a link cannot be copied automatically — the user has to select the text from the
                    // input element below this string.
                    copyLinkToClipboardFallback: '复制下面的链接',
                    // Used as the hover title and screen reader label for buttons that copy a file link.
                    copyLink: '复制链接',
                    // Used as the hover title and screen reader label for file source icons, e.g., “File source: Dropbox”.
                    fileSource: '文件来源: %{name}',
                    // Used as the label for buttons that accept and close panels (remote providers or metadata editor)
                    done: '完成',
                    // Used as the screen reader label for buttons that remove a file.
                    removeFile: '移除文件',
                    // Used as the screen reader label for buttons that open the metadata editor panel for a file.
                    editFile: '编辑文件',
                    // Shown in the panel header for the metadata editor. Rendered as “Editing image.png”.
                    editing: '正在编辑 %{file}',
                    // Text for a button shown on the file preview, used to edit file metadata
                    edit: '编辑',
                    // Used as the screen reader label for the button that saves metadata edits and returns to the
                    // file list view.
                    finishEditingFile: '结束编辑文件',
                    // Used as the label for the tab button that opens the system file selection dialog.
                    myDevice: '我的设备',
                    // Shown in the main dashboard area when no files have been selected, and one or more
                    // remote provider plugins are in use. %{browse} is replaced with a link that opens the system
                    // file selection dialog.
                    dropPasteImport: 'Drop files here, paste, %{browse} or import from',
                    // Shown in the main dashboard area when no files have been selected, and no provider
                    // plugins are in use. %{browse} is replaced with a link that opens the system
                    // file selection dialog.
                    dropPaste: '拖拽文件到这里 or %{browse}',
                    // This string is clickable and opens the system file selection dialog.
                    browse: '浏览本地文件',
                    // Used as the hover text and screen reader label for file progress indicators when
                    // they have been fully uploaded.
                    uploadComplete: '上传完成',
                    // Used as the hover text and screen reader label for the buttons to resume paused uploads.
                    resumeUpload: '继续',
                    // Used as the hover text and screen reader label for the buttons to pause uploads.
                    pauseUpload: '暂停',
                    // Used as the hover text and screen reader label for the buttons to retry failed uploads.
                    retryUpload: '重试',
     
                    // Used in a title, how many files are currently selected
                    xFilesSelected: {
                        0: '%{smart_count} 个文件已选择',
                        1: '%{smart_count} 个文件已选择'
                    },
     
                    // uppy/status-bar strings:
                    uploading: '上传中...',
                    complete: '完成'
                    // ...etc
                }
            };
            var uppy = Uppy.Core({
                autoProceed: false,
                allowMultipleUploads: true, // 上传完成之后,是否可继续添加文件上传
                restrictions: {
                    maxFileSize: 1024 * 1024 * 1024 * 4, // 以字节为单位,4G
                    maxNumberOfFiles: 100,
                    minNumberOfFiles: 1,
                    allowedFileTypes: ['image/*', 'video/*', 'img/*','text/*','html/*','application/x-zip-compressed'] // mime类型(image/png)或者文件后缀名(.jpg),zip文件
                }
            })
                .use(Uppy.Dashboard, {
                    id: 'Dashboard',
                    metaFields: [
                        { id: 'name', name: 'Name', placeholder: 'file name' }
                    ],
                    target: '#uppy-dashboard-area',
                    note: 'image and video only',
                    inline: true,
                    showLinkToFileUploadResult: true,
                    showProgressDetails: true,
                    hideUploadButton: false,
                    hideRetryButton: false,
                    hidePauseResumeButton: false,
                    hideCancelButton: false,
                    hideProgressAfterFinish: false,
                    closeModalOnClickOutside: false,
                    closeAfterFinish: false,
                    disableStatusBar: false,
                    disableInformer: false,
                    disableThumbnailGenerator: false,
                    disablePageScrollWhenModalOpen: true,
                    animateOpenClose: true,
                    proudlyDisplayPoweredByUppy: true,
                    onRequestCloseModal: () => this.closeModal(),
                    showSelectedFiles: true,
                    locale: zhcn,
                    browserBackButtonClose: false
                })
                .use(Uppy.Tus, {
                    endpoint: '/FileUpload/Upload', //服务端地址,也可以是fastdfs地址
                    chunkSize: 1024*1024*10, //客户端每patch一次请求是10M
                })
                
     
            uppy.on('file-added', (file) => {
                uppy.setFileMeta(file)
            })
            uppy.on('file-removed', (file) => {
                console.log('Removed file', file)
            })
            uppy.on('upload-success', (file, response) => {
                
            })
            uppy.on('complete', (result) => {
                console.log('Upload complete! We’ve uploaded these files:', result.successful)
            })
        </script>
    </body>
    </html>
    

  • 相关阅读:
    HTTP状态代码
    安装mySQL数据库常见问题
    python3.6安装版本选择
    用连接池提高Servlet访问数据库的效率
    策略模式
    如何在vue项目中修改less变量,多主题项目解决方案
    【前端】vue项目 url中传递数组参数
    element date-picker默认值问题
    echart 折线图legend不显示的问题
    vue学习之父子组件通信两种方法
  • 原文地址:https://www.cnblogs.com/lori/p/14918202.html
Copyright © 2020-2023  润新知