Giter Site home page Giter Site logo

Comments (4)

georgipeltekov avatar georgipeltekov commented on May 13, 2024 1

Hi,

can you try with
input.append("file", file.fileEntry);

from ngx-file-drop.

aaronjohnsonwsu avatar aaronjohnsonwsu commented on May 13, 2024

I had tried that as well but still no luck. Here is what my web api method looks like:

image

The byte array is only 18 in length which does not seem correct.

That is with the code change that you recommended:

  public uploadFile(file: UploadFile): Observable<string> {
    const endpoint = 'uploadfile';
    const url = this.uri + endpoint;

    let input = new FormData();
    input.append("file", file.fileEntry);

    return this.http.post(url, input).map(res => res.json());
  }

I was able to get the file upload working with a different route which uploaded a type "File" like this:

  public uploadFile(file: File){
    let formData: FormData = new FormData();
    formData.append('file', file, file.name); 
    this.http.post(this.apiUrl, formData);
  }

With that being said I really like how your drag and drop works but I just can't figure out what to change. Is there anything else you can think of?

from ngx-file-drop.

georgipeltekov avatar georgipeltekov commented on May 13, 2024

Hi,

can you try with:

file.fileEntry.file(info => {
uploadFile(info);
});
(please check that the uploadFile is called after the file info is taken)
where uploadFile is:
public uploadFile(file: File){
let formData: FormData = new FormData();
formData.append('file', file, file.name);
this.http.post(this.apiUrl, formData);
}

from ngx-file-drop.

aaronjohnsonwsu avatar aaronjohnsonwsu commented on May 13, 2024

That worked! Thank you so much for your help. Here is what my code looks like:

Method in Service:

  public uploadFile(file: File): Observable<string> {
    const endpoint = 'uploadfile';
    const url = this.uri + endpoint;

    let input = new FormData();
    input.append("file", file, file.name);

    return this.http.post(url, input).map(res => res.json());
  }

Dropped method (event) in the component:

  public dropped(event: UploadEvent) {
    this.files = event.files;
    for (var file of event.files) {
      file.fileEntry.file(info => {    
        this.vtootService.uploadFile(info).subscribe(res => {
          console.log(res);
        });
      });
    }
  }

Thanks again!

from ngx-file-drop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.