This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Converting a File from Memory (C#)

agilechris wrote on 2014-08-01:
Hi,

I'm using C# and when converting a file the client only seems accept a file path. Is there any way to submit a file from memory?

I want to build a zip file in memory and submit it with html, css, and images. My application is hosted in Azure Cloud, so saving a temporary file to the server is not ideal. Especially since the client would just be converting it back to a byte array before submitting it anyway.

I saw some of the Java source for the client (I'm not sure how old it was), and it seems if the CallAPI method was public I would be able to submit a byte array for the file.
support wrote on 2014-08-04:
Hello,

> I'm using C# and when converting a file the client only seems accept a file path. Is there any way to submit a file from memory?

The API client does not allow this. However, feel free to grab the client source from Github and modify it to your needs. A good place to start is the encode_multipart_post_data() method.
agilechris wrote on 2014-08-04:
That should do the trick! I'll give it a shot.

Thanks.
agilechris wrote on 2014-09-15:
I wanted to post our resolution for this in case anyone else wants to do the same thing. We use this to build a zip file in memory containing our html, css, and images for conversion. It was actually quite simple.

First we copied the code for the client as recommended, then we added an overload method for convertFile that accepted a byte array and a filename instead of just a filepath.

public void convertFile( byte[] bytes, string filename, Stream out_stream )
{
	this.post_multipart( bytes, filename, out_stream );
}


Then we added an overload for post_multipart that accepted the byte array, and the filename. It simply uses an existing overload of encode_multipart_post_data.

private void post_multipart( byte[] bytes, string filename, Stream out_stream )
{
	byte[] data = this.encode_multipart_post_data( bytes, get_mime_type(filename), filename );
	do_request( this.api_uri + "pdf/convert/html/", out_stream, data, multipart_content_type );
}
support wrote on 2014-09-16:
Hello,

Thanks for posting the resolution!