小编Sla*_*ter的帖子

使用Angular2将文件上传到REST API

实际上,我正在使用一个以Angular 2编码的接口的Spring REST API.

我的问题是我无法使用Angular 2上传文件.

我在java中的Webresources是这样的:

@RequestMapping(method = RequestMethod.POST, value = "/upload")
public String handleFileUpload(@RequestParam MultipartFile file) {
    //Dosomething 
}
Run Code Online (Sandbox Code Playgroud)

当我通过带有Auth标头等的URL请求调用它时,它完全正常工作...(使用Chrome的Advanced Rest Client扩展)

证明:(在这种情况下一切正常)

在此输入图像描述 我加了

<bean id="multipartResolver"
      class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
Run Code Online (Sandbox Code Playgroud)

Spring配置文件和Pom依赖项

<dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用webform执行相同的操作时:

<input type="file" #files (change)="change(files)"/>
<pre>{{fileContents$|async}}</pre>
Run Code Online (Sandbox Code Playgroud)

使用(更改)方法:

change(file) {
    let formData = new FormData();
    formData.append("file", file);
    console.log(formData);
    let headers = new Headers({
        'Authorization': 'Bearer ' + this.token,
        'Content-Type': 'multipart/form-data'
    });
    this.http.post(this.url, formData, {headers}).map(res => res.json()).subscribe((data) => console.log(data));
    /*
    Observable.fromPromise(fetch(this.url,
        {method: 'post', body: formData},
        {headers: …
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc angular2-forms angular2-http angular

50
推荐指数
4
解决办法
8万
查看次数

Jquery动画编号从.到

我在这里找到的动画有一个问题: jQuery动画数字计数器从零到值

这是问题所在,我在测试网站上使用它,并且计数器在大数字时没有确切的值.

这是HTML:

<span class="Count">66620</span>
 <br/>
<span class="Count">66666666</span>
 <br/>
<span class="Count">66666666</span>
Run Code Online (Sandbox Code Playgroud)

这是javascript:

$('.Count').each(function () {
  var $this = $(this);
  jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
    duration: 1000,
    easing: 'swing',
    step: function () {
      $this.text(Math.ceil(this.Counter));
    }
  });
});
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/Yy6r6/68/

有人有想法吗?

提前致谢.

javascript jquery

5
推荐指数
1
解决办法
244
查看次数