Returning a blob with NestJS - nestjs

I need to send a image as blob via a nestjs api
when i log the blob it comes perfect
console.log(blob)
but when i call it with insomnia it returns a blank object
Insomnina response
I tried calling in the front and converting to a blob again but it seems like it lost data since the size was shrink to 15 from 50k+

You may want to take a look at the official NestJs documentation about streaming files here. But first, if what you're trying to do is to return a readable stream from a buffer with no file involved, then you need to handle that buffer first as discussed in this answer. Then you can simply pipe the result using stream.pipe(res).

Related

Azure Synapse Copy Data/Web activity returning gibberish

I'm trying to create a pipeline which performs a GET call to
https://covid19.who.int/who-data/vaccination-data.csv
and save the csv file in a Synapse datalake. Other URLs are saved correctly but I cannot seem to get this URL to work. If you copy paste the URL into a browser, the CSV is downloaded perfectly fine.
I tried debugging using a Web activity, the GET call returns gibberish response.
It feels like a network problem, meaning that the GET call cannot route correctly, or something along those lines. Any idea how to resolve this?
For reference of others , I think you are seeing this
As called out in the document webactivity always expects JSON in response and in this case the response in definietely not JSON . Moreover web activity has an upper limit of 4MB as response . Just wondering when yuu say that the web activity is working for few , I am curiuos how .

Could somebody let me know in which case and which method should I use for upload / download blob?

For azure blob storage sdk of c#, there're multi methods for download / upload blob.
Download methods: DownloadText, DownloadToByteArray, DownloadToStream, DownloadToFile.
Upload methods: UploadText, UploadFromByteArray, UploadFromStream, UploadFromFile.
How do I choose these methods? like when the file is large during download/upload, and would some methods cause encode issues etc.?
Thanks.
You choose based on what you have or what you want; these things are here to make your life easy.
If you have/want a file, use the File methods (so you don't have to eg read your file into a byte array or attach a stream before uploading it, or so you can just download a file from the blob to your server)
If you have/want a stream, use the stream methods (imagine you want to send the blob data to a client, down a tcp socket - no point writing it to a file on your server then reading the file and sending it to the client, you should just open a stream from the blob and read from it and write to the rxpnsocket that goes to the client. This minimizes server resource use)
If you have/want an array, use the array methods (maybe you want to process it in memory some how)
See the docs for more info https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.storage.blob.cloudblockblob?view=azure-dotnet

How do I upload a file to a REST endpoint?

Using Twitter as an example: Twitter has an endpoint for uploading file data. https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-append
Can anyone provide an example of a real HTTP message containing, for example, image file data, showing how it is supposed to be structured? I'm fairly sure Twitter's documentation is nonsense, as their "example request" is the following:
POST https://upload.twitter.com/1.1/media/upload.json?command=APPEND&media_id=123&segment_index=2&media_data=123
Is the media_data really supposed to go in the URL? What if you have raw binary media data? Would it go in the body? How is the REST service to know how the data is encoded?
You're looking at the chunked uploader - it's intended for sending large files, breaking them into chunks, so a network failure doesn't mean you have to re-upload a 100 MB .mp4. It is, as a result, fairly complicated. (Side note: The file data goes in the request body, not the URL as a GET parameter... as indicated by "Requests should be multipart/form-data POST format.")
There's a far less complicated unchunked uploader that'll be easier to work with if you're just uploading a regular old image.
All of this gets a lot easier if you use one of Twitter's recommended libraries for your language.
to upload a file, you need to send it in a form, in node.js server you save accept the incoming file using formidable.
You can also use express-fileupload or multer

How to download file from stream with socket.io stream

I'm trying to download a file from a browser using socket.io-stream. In a basic form, this is actually doable and there is a working example here.
However, that solution:
First streams the file contents to the browser using socket.io-stream.
Assemble the chunks in the client as a blob.
Create a hidden link to the blob location.
This forces the browser to contain the whole blob in memory before it can initiate the download. I'm working with really large blobs, so that is not advisable.
I would prefere to download the stream directly, instead of buffering it in memory in the browser.
Is that possible?
I know this is easy to do just with plain HTTP, but there are some reasons that make this simplest option not available in my case.

Creating an HTML or PDF "file" in memory and streaming it in Node.js

I have a need to create a pdf or html document within a Node.js express API which then sends that document over HTTP to an API managing our CMS.
So functionally I would like to create the document and POST it as part of a multipart-form upload POST request to an external service.
I see how to do this if after I create the file, I then turn around and write it disk. After that point I can do a read stream of the file from that path to format the POST request with the file.
However I'm wondering how I can perform this action without writing the file to disk and then reading it into a read stream. It seems I should be able to accomplish this without that IO.
Anybody able to point me to a good example or library that does something along these lines?
You can extend Writable and/or Readable streams. By the first look this library do what you need, with the same way - extending built-in streams.

Resources