Binary body in postman - binary

I'm trying to send a request in binary format in postman, but it is necessary in the body no with a file.
Is there a way for do this?
Thank you all!!

Postman allows to set the body in a text based format (plain text, JSON, XML, etc) or as a binary file. If you try to copy binary data into the text box it will probably be corrupted. It is best to have the binary data in a file and attach the file.

If you are trying to send the binary as plain text it would be risky, I would suggest you to send it as a multipart format. In postman, in body you can select 'form-data' and give any key and in the 'key' field click on the drop down and select 'File' and then select the .txt file containing your binary from your local. In the mule flow give a 'set-payload' connector and in the MIME Type select 'application/octet-stream' for binary.

Related

Should I use multipart/form-data or text/csv content type for uploading CSV file to server?

I'm working on a back-end feature that involves processing CSV files uploaded by users. Most tutorials I've found so far suggest that I should read that CSV file through a multipart request.
https://www.appcoda.com/restful-api-tutorial-how-to-upload-files-to-server/
How does HTTP file upload work?
However, as far as I know, multipart requests involve a boundary and only make sense when we need to send different kinds of payload over the same request. For CSV file uploading, all I need is to send a byte stream over the request body (with the appropriate text/csv content type).
I'm not sure if there is any specific reason that people use and suggest multipart requests for uploading files?
if you use text/csv your request body should be raw text (like with json) like
"1,2,3
4,5,6"
But if you want upload file, content-type should say about it.
so, in that case i recomend to use multipart/form-data when uploading any type of files

Submiting parsed content into ElasticSearch

I am trying to upload files(.txt, .pdf) in Elasticsearch. Elasticsearch receives only content in json format. Is there any way that I send parsed content(.pdf or .txt to String) directly or I have to parse String into json document to send it to Elasticsearch.
You can only send JSON when indexing a Document, so basically, a base64 encoded version of the file in some field of that JSON will do just fine. If you do not wish to search inside this content, then all you have to do is disabling indexing on that "binary data" field (option index:false in your mapping).
If you wish to send a PDF file and have the textual content extracted and indexed / searchable, you should have a look at the Ingest Attachment Plugin.
You can look at this https://github.com/dadoonet/fscrawler for your use case.
Basically, This crawler helps to index binary documents such as PDF, Open Office, MS Office and will give you following feature
Local file system (or a mounted drive) crawling and index new files,
update existing ones and removes old ones.
Remote file system over SSH crawling.
REST interface to let you "upload" your binary documents to
elasticsearch.

What does a JSON file do?

I went through previous posts on SO and some of the answers say that a JSON file is used to send data from server to client.
Well that seems to be okay but then we can create package.json, Apidoc.json, manifest.json which do not interact with the client and server
So can someone tell me what actually is a JSON file?
JSON stands for JavaScript Object Notation. It is used to describe a data structure in a simple format. It can be a plain text file, which may be used to pass data from the server to a client, but it could be equally used to hold and consume that data at the same layer e.g. you could have a configuration file at the client side which is read an interpreted by your application.
Note also that JSON does not need to be held in a file; you could create a string variable with JSON data in it and pass this from one method to another without ever storing it in a file.
The tag definition in Stack Overflow can be found here https://stackoverflow.com/tags/json/info and further information can be found here https://www.json.org/.
JSON is a file format, just like CSV. Just because CSV is used with Microsoft Excel, does not mean that is all it is used for (just like with JSON). Just because it is common to get info from a server in JSON format, does not mean that is all JSON is used for. Do some googling before asking a question like this on Stack Overflow.
Here is an intro to JSON. JSON Intro W3Schools

Loading JSON data with CSV Data Set Config

I'm new to Jmeter so I hope this question is not too off the wall. I am trying to test an HTTP endpoint that accepts a large JSON payload and processes it. I have collected a few hundred JSON blobs in a file and want to use those as my input for testing. The only way that I have come across for loading the data is using the CSV config. I have a single line of the file for each request. I have attempted to use \n as a delimiter and have also tried adding a tab character \t to the end of each line. My requests all show in put of<EOF>.
Is there a way to read a file of JSON objects, line at a time, and pass them to my endpoint as the body in a POST?
You need to provide more information, to wit: example JSON file (first 2 lines), your CSV Data Set Configuration, jmeter.log file, etc. so we could help.
For the time being I can state that:
Given CSV file looking like:
{"foo":"bar"}
{"baz":"qux"}
And pretty much default CSV Data Set Config setup
JMeter normally reads the CSV data
Be aware that there are alternatives to the CSV Data Set Config, for example:
__CSVRead() function. The equivalent syntax would be ${__CSVRead(test.csv,0)}
__StringFromFile() function. The equivalent syntax would be ${__StringFromFile(test.csv,,,)}
See Apache JMeter Functions - An Introduction to get familiarized with the JMeter Functions concept.

box-api Download a File: how to save raw text response to file with correct encoding

I implemented downloading a file. I received raw string data. I save this data to a file, but can't open it, because file is invalid.
I tried to download jpg image.
I think this is a result of incorrect converting this data to bytes.
What Encoding I need to use?