【问题标题】:upload files with ionic file transfer使用离子文件传输上传文件
【发布时间】:2021-03-11 06:29:43
【问题描述】:

您好,我想知道是否有人可以帮助我,我想使用 ionic 文件传输将文件上传到本地主机上的服务器,我不知道该怎么做。有人可以帮助我吗?谢谢。 在首选的 Pdfs 中,但它可以是任何类型的文件

【问题讨论】:

    标签: ionic-framework file-transfer


    【解决方案1】:

    首先,您需要选择一个文件(您的图库中的图像,或您所说的 pdf)。然后获得该文件的路径:

    const fileTransfer: FileTransferObject = this.transfer.create();
    
    const options: FileUploadOptions = {
        fileKey: 'file',
        fileName: 'uploadfile',     // Name received in the server,
        mimeType: 'image/jpeg',     // or application/pdf for pdf
        headers: {...}              // (Optional) if needed
    };
    
    fileTransfer.upload( filename, url, options ).then( response => {
        // Response here
    }).catch(err => {
        // Error here
    });
    

    Filename 是您设备中文件的路径(所选的 pdf 文件),而 url 是您要上传的服务器的 url。

    【讨论】:

    • 感谢回复,我已经卸载了插件,因为它已经过时了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-04
    • 2016-05-14
    • 2013-01-18
    • 2014-06-28
    • 1970-01-01
    相关资源
    最近更新 更多