The API's Documentation said I should put in Body Params:
restaurant_token:(required)string -> API Access Token providen by Tiller
provider_token:(required)string -> API Access Token providen by Tiller
inventory:(required)file -> Inventory import file
clear:(booleantrue) -> remove existing items or not
My POST request is :
https://app.tillersystems.com/api/inventory/import
And my JSON is:
{
"provider_token": "xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"restaurant_token": "xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"inventory": "C://Mes Projets//N74_Interface_Sage_Tiller//Exe//Traitement//Articles_SAGE_20210826172848541.csv",
"clear": true
}
The request's answer is:
{
"import": false,
"message": "Missing \"inventory\" file field."
}
You can encode file to base64 and put it as string like this
But I think the best solution is to use standard file sharing protocols
To send large files, in any case, you will have to send them in their original form, without convertation to base64
To download files on the client, you can receive data about the file in the json format, which will include the generated link to download the file using the standard protocol
Related
I have an Azure Logic App that uses a Analyze Document for Prebuilt or Custom models (v3.0 API) action. The Custom Model is good, I can hit it with Postman with no issue.
When I try to get a PDF from Sharepoint and send it to the service, I get an error saying:
{
"error": {
"code": "InvalidRequest",
"message": "Invalid request.",
"innererror": {
"code": "InvalidContent",
"message": "The file is corrupted or format is unsupported. Refer to documentation for the list of supported formats."
}
}
}
I've tried:
Passing the Get file content directly to the Document/Image File Content input
Passing body('Get_file_content)['$content']
Passing concat('data:application/pdf;base64,',body('Get_file_content')['$content']
This one converts to PDF in a Base64-to-PDF tool so I know the Base64 is good
Then I found out that the service wants binary format:
Passing base64ToBinary(body('Get_file_content')['$content'])
Still no go
Why can I not send the file to the Form Recognizer service?
EDIT:
Thank you to #vijaya. They helped me see that the Document/Image URL parameter was not necessary. Leaving that blank and using the original Get File Content worked!
Issue is with content-type. You need to pass content-type along with content for analyze document. I have reproduced issue from my side and below are steps I followed,
Initially created logic app as shown below,
Logic app failed with error,
The file is corrupted or format is unsupported. Refer to documentation for the list of supported formats.
Next modified logic app as shown below,
In Compose action setting content as
outputs('Get_blob_content_(V2)')?['body']?['$content'] and passing content-type as application/pdf as we are dealing with pdf files.
In Analyze Document for Prebuilt or Custom models (v3.0 API) action, using outputs of compose in Document/Image File Content.
Logic app ran successfully as shown below,
Output of Analyze Document is as shown below,
I'm new in it and trying to understand Azure Logic Apps.
I would like to create a LogicApp that:
Looks for new XML-Files
and for each file:
Read the XML
Check if Node "attachment" is present
and for each Attachment:
Read the Filename
Get the File from FTP and do BASE64-encoding
End for each Attachment.
Write JSON File (I have a schema)
DO HTTP-Post to API with JSON file as "application/json"
Is this possible with the Logic-Apps?
Yes, you can.
Check if a node is present, with xpath expression (e.g. xpath(xml(item()),'string(//Part/#ref)'))
For Get File from FTP, use the action FTP - Get File Content
Write JSON File, use the action Data Operations - Compose. If you need transformations, you have to use an Integration Account and Maps.
Do HTTP Post to API, use de action HTTP
I have recorded my script to upload json file through Jmeter, but now I am facing the problem while uploading json file through jmeter which is on my local drive.
I am already done with following steps:
Either use full path to file, you're uploading, or copy it to JMeter's "bin" folder
Don't forget to tick Use multipart/form-data for HTTP POST box
Make sure you provide correct Parameter name and MIME Type
Getting exception in my response data:
{"Exception":"Object reference not set to an instance of an object."}
For me works like this. JSON example May be Your server prefer some specific headers? E.g. content type and so on
Why you're using json file?
If you facing problems with generating random JSON data, here is a JSR223 preprocessor:
import org.apache.commons.io.FileUtils;
def time = vars.get("stratup_time")
File myFile = File.createTempFile("upload-", "" );
// Generate Random length string and write to file
FileUtils.write(myFile, "{\"test\":\"$time\"", "UTF-8" )
// Store file name in variable.
vars.put( "filename", myFile.getCanonicalPath() )
And PostProcessor:
import org.apache.commons.io.FileUtils;
// Delete file and do not throw error
FileUtils.deleteQuietly(new File( vars.get("filename")));
In order to be able to record the file upload event you need to copy your .json file to JMeter's "bin" folder, this way HTTP(S) Test Script Recorder will be able to capture the request and generate necessary HTTP Request sampler. It will also populate the HTTP Header Manager
More information: Recording File Uploads with JMeter
Whatever data I want to send whether be a text file or a PDF am able to give but how do I give my desired name to the file ?? And what about other types of files ?? What should be the request header please give an example had a look at the API documentation but not getting it ...
It seems you're using a basic upload.
You can use the suggested answer in this SO post:
Use multipart upload and specify the tile in the metadata part
{
"title": "My File"
}
Types of files are called MiME types. You can see the supported MiME types here.
Check this Multipart Upload guide for more info.
Right now we have a web application which upload a file using multipart in spring . now we are converting it as a rest webservices with JSON to a mobile application. how to send file details to rest webservice controller using json.
Simple
This is stateless.
Send JSON similar to this:
{ "fileName" : "the file name",
"contents" : "the file contents"
}
Be sure to use JSON escaping of the file contents and the file name.
Not Great
This requires state (not a good thing for a rest controller).
Call1: Post to .../beginUpload
Description: starts a file upload.
Parameter:
filename
ReturnValue: some identifer (called FileId below).
Call2: Post to .../fileContents
Desciption: adds some contents to an already open file.
Call this one or more times until the file contents are fully transferred.
Parameters:
fileId, contents.
ReturnValue: success / failure
Call3: Post to .../endUpload
Description: ends a file upload.
Parameter:
fileId
ReturnValue: success / failure
Challenge: the rest server may need to timeout uploads that have not had a call to .../fileContents in x minutes.
Different
Have the mobile device send an email containing the file to be uploaded.
Implement something to monitor the emailbox to which the file upload emails are sent and do "the right stuff".