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

csharp generated client sdk file upload doesn't work #5618

Closed
joelharkes opened this issue May 11, 2017 · 2 comments
Closed

csharp generated client sdk file upload doesn't work #5618

joelharkes opened this issue May 11, 2017 · 2 comments

Comments

@joelharkes
Copy link

joelharkes commented May 11, 2017

I'm not sure if the problem is RestSharp or Swaggers but when you generate a file upload it doesnt work. It doesn't even send an http request (checked on receiving server and with fidller4)

A workaround fix i used to make it work was this: (But its a terrible hack):

public partial class ApiClient
{
	partial void InterceptRequest(IRestRequest request)
	{
		var files = request.Files.Select(x => x).ToArray();
		request.Files.Clear();
		foreach (var file in files)
		{
			var t = new MemoryStream();
			file.Writer(t);
			request.AddFileBytes(file.Name, t.ToArray(), file.FileName, file.ContentType);

		}
	}

}

the yaml file i used:

  /files/{eextra}/submit:
    post:
      description: |
        Upload a new file
      operationId: uploadFile
      consumes:
        - multipart/form-data
        - application/x-www-form-urlencoded
      tags:
        - Files
      parameters:
        - name: extra
          in: path
          description: extra name
          required: true
          type: string
          default: none
        - name: file
          in: formData
          description: The uploaded file data
          required: true
          type: file
        - name: filename
          in: formData
          description: The name of the file
          required: true
          type: string
        - name: overwrite
          in: formData
          description: Overwrite if exists
          required: true
          type: boolean
          default: true
        - name: prefix
          in: formData
          description: The prefix/folder to upload file to
          required: false
          type: string
          default: "/"
      responses:
        200:
          description: files response
        400:
          description: Bad Request/Validation error
          schema:
            $ref: '#/definitions/Error'
        default:
          description: unexpected error
          schema:
            $ref: '#/definitions/Error'

version: swagger gen 2.2.2

@wing328
Copy link
Contributor

wing328 commented May 12, 2017

@joelharkes which version of RESTSharp library are you using? The latest one has issue with file upload if I remember correctly.

Did you have a chance to take a look at #2175 ?

You can also pull the latest to generate C# API client with RestSharp.portable instead of RestSharp

@joelharkes
Copy link
Author

Ah I see thanks :) ya seems the same issue:)

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

2 participants