【发布时间】:2021-03-11 06:29:43
【问题描述】:
您好,我想知道是否有人可以帮助我,我想使用 ionic 文件传输将文件上传到本地主机上的服务器,我不知道该怎么做。有人可以帮助我吗?谢谢。 在首选的 Pdfs 中,但它可以是任何类型的文件
【问题讨论】:
标签: ionic-framework file-transfer
您好,我想知道是否有人可以帮助我,我想使用 ionic 文件传输将文件上传到本地主机上的服务器,我不知道该怎么做。有人可以帮助我吗?谢谢。 在首选的 Pdfs 中,但它可以是任何类型的文件
【问题讨论】:
标签: ionic-framework file-transfer
首先,您需要选择一个文件(您的图库中的图像,或您所说的 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。
【讨论】: