Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Typescript][Angular] File uploads not working #6789

Closed
itsTeknas opened this issue Oct 23, 2017 · 2 comments
Closed

[Typescript][Angular] File uploads not working #6789

itsTeknas opened this issue Oct 23, 2017 · 2 comments

Comments

@itsTeknas
Copy link

Description

Methods generated with the client generated by angular2-typescript do not handle file uploads properly.

Swagger-codegen version

Live editor.swagger.io version. I don't know which one they use.

Swagger declaration file content or url

Any method declared with a file is affected.

/upload_doc:
    post:
      consumes: 
        - multipart/form-data
      parameters: 
        - name: file
          type: file
          in: formData
          required: true
      responses:
        200:
          description: OK

Generates something like :

headers.set('Content-Type', 'application/x-www-form-urlencoded');

        if (file !== undefined) {
            formParams.set('file', <any>file);
        }

        let requestOptions: RequestOptionsArgs = new RequestOptions({
            method: RequestMethod.Post,
            headers: headers,
            body: formParams.toString(),   <-----  is this correct ?
            search: queryParameters,
            withCredentials:this.configuration.withCredentials
        });
Suggest a fix/enhancement

The Following typescript code seems to works fine to post a file to a server.

const formData: FormData = new FormData();
formData.append('file', file, file.name);
this.http.post(target, formData, options);

P.S. I'm new with angular, i might be making some mistakes calling the method which i am not aware of.

@wing328
Copy link
Contributor

wing328 commented Oct 25, 2017

Live editor.swagger.io version. I don't know which one they use.

Please try the latest master (2.3.0), which has a lot of enhancements. SNAPSHOT version of 2.3.0 JAR can be found in the project's README.

@macjohnny
Copy link
Contributor

macjohnny commented Oct 25, 2017

@itsTeknas @wing328 this was fixed with #6574 (#6457)

@wing328 wing328 closed this as completed Dec 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants