Aurelia JS FIE上传到服务器 [英] Aurelia js fie upload to server

查看:62
本文介绍了Aurelia JS FIE上传到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你是aurelia js的新手,我需要使用autrelia js,materializecss和httpClient.fetch将文件上传到服务器,进行api调用.我不知道如何将文件发送到服务器.

Hi am new to aurelia js , i need to upload file to server,am using autrelia js, materializecss and httpClient.fetch for api call. I dont'know how to send file to server.

视图:

<input type="file"  files.bind="selectedFiles" change.delegate="onSelectFile($event)">

型号:

  onSelectFile(e)
{
   var myurl = 'http://cdn.dmsapp.tk/file?authToken=bLNYMtfbHntfloXBuGlSPueilaHtZx&type=jpg&name=sibi.jpg&userId=7&organizationId=1&sourceType=USER_UPLOADS';
        this.httpValueConverter.call_http(myurl,'POST',this.selectedFiles[],'fileupload',file_upload)
            .then(data => {
            console.log(data);
        if(data.meta && data.meta.statusCode == 200) {
          //  this.index_lists = data.index.list;
        }
    }); }

httpservice:

httpservice :

 return this.httpClient.fetch('http://api.dmsapp.tk/'+url,
            {
                method: method,
                body : json(myPostData),
                headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'authorization': this.authorization}})
            .then(response => response.json());

寻找解决方案.

推荐答案

如果它是文件,并且您正在尝试上传特定的媒体类型, 标题"Content-Type":"application/x-www-form-urlencoded"对我来说似乎不正确.在这里查看适当的媒体类型:

If it's a file and you are trying to upload a particular media type, the header 'Content-Type': 'application/x-www-form-urlencoded' does not seem right to me. Have a look at the appropriate media type here:

http://www.iana.org/assignments/media- types/media-types.xhtml

另外,您将数据序列化为JSON,如果您的数据是二进制的,则需要将其更改为字节数组.

Also, you serialize data to JSON, if your data is binary you will need to change that to a byte array.

您可能会在这里找到一些有用的信息:

You might find some useful info here:

http://www.petermorlion.com/file-upload-with-aurelia/

还要在URL和标头中都设置一个令牌,我建议仅在标头中设置它.

Also you set a token both in your URL and your header, I'd recommend to set it in the header only.

这篇关于Aurelia JS FIE上传到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆