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

Cannot include the file name or file extension when uploading a file from a MemoryStream using FileService.cs #2634

Open
FunctionallyLiterate opened this issue Jan 19, 2023 · 5 comments

Comments

@FunctionallyLiterate
Copy link

FunctionallyLiterate commented Jan 19, 2023

Describe the bug

When uploading a file using FileService.cs we need the ability to set the file name and content type. Currently, if you try to upload a file using the FileCreateOptions.cs class with any type of Stream other than a FileStream it will get the default file name of "blob" with a default content type.

Our use case is to allow a user to upload their dispute evidence to our application, then send the file to Stripe using a MemoryStream. The current code in this .Net library doesn't allow us to change the file name or content type in that scenario. We'd really rather not switch to FileStream since that class is meant to be used for interacting with files stored on disk, which we don't want to do.

The culprit seems to be this code:

private static StreamContent CreateStreamContent(Stream value, string name)

image

Would it be possible to include FileName and ContentType as parameters to this class and plumb them through when uploading a file?

public class FileCreateOptions : BaseOptions

To Reproduce

var fileService = new FileService();

var options = new FileCreateOptions
{
File = new MemoryStream(),
Purpose = FilePurpose.DisputeEvidence
};

var uploadResult = await fileService.CreateAsync(options);

Expected behavior

We should be able to set the File name and Content Type.

Code snippets

var fileService = new FileService();

 var options = new FileCreateOptions
                        {
                            File = new MemoryStream(),
                            Purpose = FilePurpose.DisputeEvidence
                        };

var uploadResult = await fileService.CreateAsync(options);

OS

Windows 10

.NET version

.Net 6.0

Library version

stripe-dotnet v39.75.1

API version

2020-08-27

Additional context

No response

@pakrym-stripe
Copy link
Contributor

This is a good idea, we are going to look into implementing it in the future.

@FunctionallyLiterate
Copy link
Author

Awesome! That's good to hear.

@AraHaan
Copy link
Contributor

AraHaan commented Apr 7, 2023

I think I could look into this when I get more time.

@CGollhardt
Copy link

Was just about opening the same issue. Do you have any time frame? @pakrym-stripe

@AraHaan
Copy link
Contributor

AraHaan commented Jun 29, 2023

I think a option for uploading the file using ReadOnlySpan<byte> should be possible as well for performance critical applications as well (think things like hospital applications for example where every bit of performance it critical to do anything and everything and can sometimes mean life or death).

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

4 participants