Skip to content

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

Open
@FunctionallyLiterate

Description

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

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions