I'm trying to semd a base64 encoded fimage to the ocr.space api following https://ocr.space/blog/2016/10/ocr-api-supports-base64.html and https://ocr.space/ocrapi . You can see my Postman settings in the screenshot.
However when I submit it I see:
"ErrorDetails": "Not a valid base64 image. The accepted base64 image format is 'data:<content_type>;base64,<base64_image_content>'. Where 'content_type' like 'image/png' or 'image/jpg' or 'application/pdf' or any other supported type.",
Using Postman I have created the following curl request https://pastebin.com/ajfC3a5r
What am I doing wrong
How about this modification?
Modification points:
In your base64 data at here, \n is included.
When I tried to decode the base64 data after \n was removed from the base64 data, it was found that the data was PDF file. The content type was not image/png.
By these, I think that the error which was shown at your question occurs. So please modify as follows.
Modified curl command:
Please remove \n from the base64 data.
About the header of base64 data, please modify from data:image/png;base64,##### base64 data ##### to data:application/pdf;base64,##### base64 data #####.
When above modifications were done, how about using the following curl command?
curl -X POST \
https://api.ocr.space/parse/image \
-H "apikey:#####" \
-F "language=eng" \
-F "isOverlayRequired=false" \
-F "iscreatesearchablepdf=false" \
-F "issearchablepdfhidetextlayer=false" \
-F "base64Image=data:application/pdf;base64,##### base64 data #####"
Result:
When above sample is run, the following value is returned.
{
"ParsedResults": [
{
"TextOverlay": {
"Lines": [],
"HasOverlay": false,
"Message": "Text overlay is not provided as it is not requested"
},
"TextOrientation": "0",
"FileParseExitCode": 1,
"ParsedText": "##### text data #####",
"ErrorMessage": "",
"ErrorDetails": ""
}
],
"OCRExitCode": 1,
"IsErroredOnProcessing": false,
"ProcessingTimeInMilliseconds": "123",
"SearchablePDFURL": "Searchable PDF not generated as it was not requested."
}
Note:
In my environment, I could confirm that the API worked using above modified base64 data and sample curl.
The curl sample including the modified base64 data is this.
If you use this, please set your API key.
Or you can also directly use the image file which is not base64 data. The sample curl is
curl -X POST https://api.ocr.space/parse/image -H "apikey:#####" -F "file=#sample.png"
Related
I'm now using the mock server from https://www.mock-server.com/ and run it in a docker container.
Now I would like to let the response change as request body changes. I've looked up for dynamic response on official webiste for a while, but have no idea on how to extract specific data from request body.
curl -v -X PUT "http://localhost:1080/mockserver/expectation" -d '{
"httpRequest": {
"path": "/some/path"
},
"httpResponseTemplate": {
"template": "return { statusCode: 200, body: request.body };",
"templateType": "JAVASCRIPT"
}
}'
The code above is to create a simple expectation, which will response the request body. For example,
$curl http://localhost:1080/some/path -d '{"name":"welly"}'
{"name":"welly"} //response
Now I want to change the way of giving the response. For example, I would like to input {a:A, b:B} and get the response {a:B, b:A}.
So, how to modify the json data in request body and give it to response? I guess there are some methods to extract specific data from json file, or modify json data, etc. Also, I want to know how to better search the detailed information, since the official website and full REST API json specification
(https://app.swaggerhub.com/apis/jamesdbloom/mock-server-openapi/5.11.x#/expectation/put_expectation) is hard for me to understand.
Thanks a lot!
I needed to do this as well, I think I got this to work have a look at my curl example for the expectation I hope that helps:
curl -v -X PUT "http://localhost:1080/mockserver/expectation" -d '{
"httpRequest": {
"path": "/api/fun",
"method": "POST"
},
"httpResponseTemplate": {
"template": "
req = JSON.parse(request.body.string)
rid = req[\"id\"]
return { statusCode: 201, body: {new_id: rid} }
",
"templateType": "JAVASCRIPT"
}}'
After you do this if send:
curl -X POST http://localhost:1080/api/fun --data '{"id": "test_1"}'
it should return:
{ "new_id" : "test_1" }
Javascript templating supported via Nashorn engine and thus will no longer be available from Java 15. Here is the note from the Mockserver docs.
From Java 15 Nashorn is no longer part of the JDK but it is available as a separate library that requires Java 11+. Once MockServer minimum Java version is 11 then this separate library will be used.
The documentation and help for this particular Segment.io is limited and sparse, so I hope it's OK to ask in here.
I have just set up a Segment.io workspace and a HTTP API source
Per the docs, I sent some POST requests (with Postman) to the https://api.segment.io/v1/track and https://api.segment.io/v1/page endpoints. The requests were structured like this:
curl -X POST \
https://api.segment.io/v1/track \
-H 'Accept: */*' \
-H 'Authorization: My4w3s0m3k3y' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Host: api.segment.io' \
-H 'Postman-Token: 474d7fbe-15af-43d2-b629-61e15945e662,2c3d5fbe-2c09-4fe6-b7ea-a04e3221201b' \
-H 'User-Agent: PostmanRuntime/7.11.0' \
-H 'accept-encoding: gzip, deflate' \
-H 'cache-control: no-cache' \
-H 'content-length: 117' \
-d '{
"userId": "abc123",
"event": "My tests",
"properties": {
"name": "test 1"
}
}'
which all returned a 200 response and the following message:
{
"success": true
}
However, when I got to my dashboard, no events have been recorded.
The debugger is also empty
What am I missing here?
It looks like your write key isn't base64 encoded. When you encode your write key, remember to add the : at the end of it, before it's encoded.
Also, for the Authorization key:value, be sure to add Basic before the encoded write key. So your Authorization key:value would look like:
Authorization: Basic {encoded write key}
An example from the segment documentation:
In practice that means taking a Segment source Write Key,'abc123', as the username, adding a colon, and then the password field is left empty. After base64 encoding 'abc123:' becomes 'YWJjMTIzOg=='; and this is passed in the authorization header like so: 'Authorization: Basic YWJjMTIzOg=='.
I have been dealing with the same issue.
I found the solution as Todd said.
You should add a header Authorization: Basic + base64 encoding write key.
So, you look for the Segment source setting and get the write key.
After that, i have used an online base64 encoding tool to encode my write key.
Finally, you should add this header (Authorization) with 'Basic' and the encoded write key.
You should be able to see the tracked event in the Debugging panel in Segment web page.
I hope this helps!
You can try this code
const { promisify } = require("util");
var Analytics = require("analytics-node");
var analytics = new Analytics("xxxxxxxxxxxxxxxxxxxxxxx", {
flushAt: 1,
});
const [identify, track] = [
analytics.identify.bind(analytics),
analytics.track.bind(analytics),
].map(promisify);
console.log("user id: ", req.body.event.app_user_id);
let app_user_id = req.body.event.app_user_id;
let period_type = req.body.event.period_type;
let expiration_at_ms = req.body.event.expiration_at_ms;
let ret = "Initial";
try {
await identify({
userId: app_user_id,
traits: {
period_type: period_type,
expiration_at_ms: expiration_at_ms,
},
});
ret = "Done : Sengment done";
} catch (err) {
console.log("err: ", err);
ret = "Error : " + err;
}
return {
rafsan: ret,
};
Try to clear your browser's cache or use a different browser. I had the same problem and worked for me.
Hope this helps.
I've tried to write equivalent karate script for below curl request
curl -X PUT \
'http://localhost:8055/uploadfile' \
-H 'content-type: multipart/form-data;' \
-F code=#/Users/test/Downloads/Next.zip
Tried karate script
Given path 'uploadfile'
#Given header Content-Type = 'multipart/form-data'
And form field code = '/Users/test/Downloads/Next.zip'
#And multipart file code = { read: '/Users/test/Downloads/Next.zip' , contentType: 'application/zip' }
When method PUT
Then status 200
Am I doing something mistake here (tried different things)? Still not getting expected API response.
FYI : I've got that curl command from postman and it is working fine.
It is hard to tell with the limited info you have provided. Try this:
Given url 'http://localhost:8055/uploadfile'
And multipart file code = { read: 'file:/Users/test/Downloads/Next.zip', filename: 'Next.zip', contentType: 'application/zip' }
When method put
If you are still stuck follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue (or use postman ;)
I am currently using this command in terminal to try transcribe my telephonic mono voice sample wav with 16 bps at 8 kHz sample rate, to the IBM Speech-to-Text engine.
curl -X POST \
-u "apikey goes here" \
--header "Content-Type: audio/wav", "model: en-US_NarrowbandModel" \
--data-binary #{path_url_goes_here)/OSR_us_000_0010_8k.wav \
"https://stream.watsonplatform.net/speech-to-text/api/v1/recognize"
The output, however, states that input wav is unsupported:
curl: (3) Port number ended with ' '
{
"code_description": "Unsupported Media Type",
"code": 415,
"error": "Unable to transcode from audio/wav, to one of: audio/x-float-array; rate=16000; channels=1, application/srgs, application/srgs+xml, application/jsgf, application/fsm, application/bnf"
}
According to IBM supported audio format list, I have changed my model to "NarrowbandModel" to allow the minimum input sampling rate of 8 kHz as stated.
My question:
Is there something wrong with my request or audio file?
Update: I have tried converting the .wav to the MP3 format at constant 8 and 48 kHz sampling rate. With the changes to "Content-Type: audio/mp3", also result in the same output as mentioned above.
Try passing the model=en-US_NarrowbandModel as parameter in the URL. Following curl command works for me for your wav file.
curl -X POST \
-u "apikey:XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type:audio/wav" \
--data-binary #OSR_us_000_0010_8k.wav \
"https://stream.watsonplatform.net/speech-to-text/api/v1/recognize?model=en-US_NarrowbandModel"
{
"results": [
{
"alternatives": [
{
"confidence": 0.985,
"transcript": "the birch canoes slid on the smooth planks "
}
],
"final": true
},
I`m trying to upload image in a project in gitlab. According to documentation
it should not be a rocket science. I have tried to pass the image as url and base-64 representation. If I encode the base-64 URL there is a little progress - internal server error. Any ideas? Thanks!
Since you don't mentioned how you want upload..
With curl:
curl --request POST --header "PRIVATE-TOKEN: XXXXXXXXXX" --form "file=#dk.png" https://gitlab.example.com/api/v4/projects/5/uploads
5 is the id of your project.
gitlab api doc
According to this post :
Encoding an image file with base64
we could understand how to convert binary files to a base64 string including image, zip or pickle etc.
This is apart of my code. Hope it is helpful.
import gitlab
def test_upload_img_to_repo():
gitlab.Gitlab(url=HOST, private_token=PERSONAL_TOKEN)
project = gl.projects.get(project_id)
file_path = path.join(path.dirname(__file__), 'test_upload.txt')
img_path = path.join(path.dirname(__file__), 'logo.png')
data = {
'branch': 'master',
'commit_message': 'blah blah blah',
'actions': [
{
'action': 'update',
'file_path': 'upload.txt',
'content': open(file_path).read(),
},
{
# Binary files need to be base64 encoded
'action': 'create',
'file_path': '/folder/logo.png',
'content': base64.b64encode(open(img_path,'rb').read()).decode(),
'encoding': 'base64',
}
]
}
commit = project.commits.create(data)
print(commit)