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

Refitter fails to generate FormData parameter for file upload #62

Closed
richardhu-lmg opened this issue Jun 7, 2023 · 6 comments · Fixed by #65
Closed

Refitter fails to generate FormData parameter for file upload #62

richardhu-lmg opened this issue Jun 7, 2023 · 6 comments · Fixed by #65
Assignees
Labels
bug Something isn't working

Comments

@richardhu-lmg
Copy link

Describe the bug

Refitter ignores the IFormFile parameter decorated with [FromForm] which is used for receiving file upload.
The controller parameter is completely missed in the generated refit interface method.

If it worked, the generated method would have [Multipart] as method annotation and StreamPart as the type for IFormFile parameter
https://github.com/reactiveui/refit#multipart-uploads

Support Key: 8hz0dgn

OpenAPI Specifications
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"formFile": {
"type": "string",
"format": "binary"
}
}
},
"encoding": {
"formFile": {
"style": "form"
}
}
}
}
}

Additional context

@christianhelle
Copy link
Owner

@richardhu-lmg thanks for taking the time to report this. Multi-part upload support is currently not implemented yet but I will add it to my to-do list

@christianhelle christianhelle self-assigned this Jun 7, 2023
@christianhelle christianhelle added the bug Something isn't working label Jun 7, 2023
@richardhu-lmg
Copy link
Author

@richardhu-lmg thanks for taking the time to report this. Multi-part upload support is currently not implemented yet but I will add it to my to-do list

Any estimate re when the fix will be implemented?

@christianhelle
Copy link
Owner

@richardhu-lmg thanks for taking the time to report this. Multi-part upload support is currently not implemented yet but I will add it to my to-do list

Any estimate re when the fix will be implemented?

@richardhu-lmg Sorry, I can't really honestly say when I'll implement this. I'll try looking into how complex this is tonight, and if it's simple enough, it will probably be done in a few minutes or hours. Otherwise, it will be completed when I find the time.

@richardhu-lmg You are more than welcome to give it a shot yourself and create a pull request, I'm very open and lenient regarding pull requests

@christianhelle
Copy link
Owner

@all-contributors please add @richardhu-lmg for bugs

@allcontributors
Copy link
Contributor

@christianhelle

I've put up a pull request to add @richardhu-lmg! 🎉

@christianhelle
Copy link
Owner

I have an implementation where the following OpenAPI v3 specifications

{
   "openapi":"3.0.2",
   "paths":{
      "/foo/{id}/files":{
         "post":{
            "summary":"uploads a file",
            "operationId":"uploadFile",
            "parameters":[
               {
                  "name":"id",
                  "in":"path",
                  "description":"Id of the foo resource",
                  "required":true,
                  "schema":{
                     "type":"integer",
                     "format":"int64"
                  }
               }
            ],
            "requestBody":{
               "content":{
                  "multipart/form-data":{
                     "schema":{
                        "type":"object",
                        "properties":{
                           "formFile":{
                              "type":"string",
                              "format":"binary"
                           }
                        }
                     },
                     "encoding":{
                        "formFile":{
                           "style":"form"
                        }
                     }
                  }
               }
            },
            "responses":{
               "200":{
                  "description":"successful operation"
               }
            }
         }
      }
   }
}

Generates the following Refit interface

public interface IApiClient
{
    [Multipart]
    [Post("/foo/{id}/files")]
    Task UploadFile(long id, StreamPart formFile);
}

@richardhu-lmg Will this work for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants