Google Cloud Video Intelligence API - InvalidArgumentException/StatusRuntimeException INVALID_ARGUMENT: Request contains an invalid argument - kotlin

When I try to transcribe some video's I do get the following error message:
java.util.concurrent.ExecutionException: com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Request contains an invalid argument.
at com.google.common.util.concurrent.AbstractFuture.getDoneValue(AbstractFuture.java:553) ~[guava-28.2-android.jar!/:na]
at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:432) ~[guava-28.2-android.jar!/:na]
at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get(FluentFuture.java:93) ~[guava-28.2-android.jar!/:na]
at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:68) ~[guava-28.2-android.jar!/:na]
at com.google.api.gax.longrunning.OperationFutureImpl.get(OperationFutureImpl.java:133) ~[gax-1.53.0.jar!/:1.53.0]
In the process MP4 video's are converted to WEBM so we are able to stream the video's correctly in our frontend. There seems to be a problem with the ByteArray of the WEBM file we pass to the request, so I tried to pass the ByteArray of the MP4 file directly. Unfortunately I did get the same error here with multiple MP4 files. There are also some MP4 files which are transcribed succesfully. So I don't know what is wrong with the ByteArray and how to fix this problem.
Our AnnotateVideoRequest is builded in this way:
private fun buildRequest(
videoBytes: ByteString,
transcriptionLanguage: String
): AnnotateVideoRequest {
val config: SpeechTranscriptionConfig = SpeechTranscriptionConfig
.newBuilder()
.setLanguageCode(transcriptionLanguage)
.setEnableAutomaticPunctuation(this.enableAutomaticPunctuation)
.setMaxAlternatives(this.maxAlternatives)
.build()
val context: VideoContext = VideoContext
.newBuilder()
.setSpeechTranscriptionConfig(config)
.build()
return AnnotateVideoRequest
.newBuilder()
.setInputContent(videoBytes)
.addFeatures(Feature.SPEECH_TRANSCRIPTION)
.setVideoContext(context)
.build()
}
We make use of the of the following version of the client library: com.google.cloud:google-cloud-video-intelligence:1.2.1
What are possible ways to determine what is actually going wrong when performing this request with some of our MP4 files?

I debugged it and I only get this error if i send file bytes as "inputContent". If i have file in google cloud and i send file url as "inputUri" then i do not get any error. (used gs://cloud-samples-data/video/cat.mp4" as sample for testing)

Related

React Native FileSystem file could not be read? What the Blob?

I am trying to send an audio file recorded using expo-av library to my server using web sockets.
Websocket will allow me to only send String, ArrayBuffer or Blob. I spent whole day trying to find out how to convert my .wav recording into a blob but without success. I tried to use expo-file-system method FileSystem.readAsStringAsync to read the filed as a string but I get an error that the file could not be read. How is that possible? I passed it the correct URI (using recording.getURI()).
I tried to re-engineer my approach to use fetch and FormData post request with the same URI and audio gets sent correctly. But I really would like to use WebSockets so that later I could try to make it stream the sound to the server in real time instead of recording it first and then sending it.
You can try ... But I can't find a way to read the blob itself
// this is from my code ...
let recording = Audio.Recording ;
const info = await FileSystem.getInfoAsync(recording.getURI() || "");
console.log(`FILE INFO: ${JSON.stringify(info)}`);
// get the file as a blob
const response = await fetch(info.uri);
const blob = await response.blob(); // slow - Takes a lot of time

Sending files using pure HTTP request using telegram bot

hello everyone I was tring to send files using my bot like http://api.telegram.org/botTOKEN/sendDocument?document=http://my_path&chat_id but it ain't support .txt .docx..... and other formats..... any help please
According to https://core.telegram.org/bots/api#sending-files
Sending by URL In sendDocument, sending by URL will currently only
work for gif, pdf and zip files.
You may try to use this approach
Post the file using multipart/form-data in the usual way that files
are uploaded via the browser. 10 MB max size for photos, 50 MB for
other files.
This answer might give you some ideas on how to do that.
UPDATE
It is also good idea to use someone's library to understand how it works there.
For example, I use longman/telegram-bot from this repo. There is encodeFile method in Request class.
Method is follows:
public static function encodeFile($file)
{
$fp = fopen($file, 'rb');
if ($fp === false) {
throw new TelegramException('Cannot open "' . $file . '" for reading');
}
return $fp;
}
Which means simple fopen method with 'rb' parameter is enough to convert file.

ArrayIndexOutOfBoundsException use karate 0.8.0 [duplicate]

I'm trying to upload images on specific slack channel using Karate but no luck, I tried multiple times with different steps but still have 200 response and the image is not displayed in the channel.
Tried to post text content and successfully found the text on the channel.
Bellow are 2 of my tries following the Karate documentation:
#post
Feature: Post images
Background:
* url 'https://slack.com/api/files.upload'
* def req_params= {token: 'xxxxxxx',channels:'team',filename:'from Karate',pretty:'1'}
Scenario: upload image
Given path 'api','files'
And params req_headers
And multipart file myFile = { read: 'thumb.jpg', filename:
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field message = 'image upload test'
And request req_headers
When method post
Then status 200
OR
Given path 'files','binary'
And param req_params
And request read('thumb.jpg')
When method post
Then status 200
Am I missing something? Tried the same examples found in Karate demo GitHub repository of uploading pdf and jpg but no luck.
Note: worked using Slack API UI.
You seem to be mixing up things, there is no need for a request body when you are using multipart. Your headers / params look off. Also based on the doc here, the name of the file-upload field is file. Try this:
Scenario: upload image
Given url 'https://slack.com/api/files.upload'
And multipart file file = { read: 'thumb.jpg', filename:
'upload-name.jpg', contentType: 'image/jpg' }
And multipart field token = 'xxxx-xxxxxxxxx-xxxx'
When method post
Then status 200
If this doesn't work, take the help of someone who can understand how to interpret the Slack API doc. Or get a Postman test working, then you'll easily figure out what you missed.

How to POST a XML file in jmeter body instead of a physical file

I'm using JMeter 3.2.
My requirement is to read an XML file from the disk, replace some tags with dynamic values to ensure each thread sends a unique xml file upload (NOT SOAP Request). The following code in JSR223 sampler works perfectly fine when I try to upload the newfile through POST using a http sampler with ${newfilename} file text/xml.
import org.apache.commons.io.FileUtils;
try {
String content = FileUtils.readFileToString(new File("E:/test.xml"));
content = content.replaceAll("SUB_ID", "${__UUID}");
content = content.replaceAll("ABN_ID", "${empabn}");
content = content.replaceAll("EMPNAME", "${empname}");
vars.put("content", content);
FileUtils.writeStringToFile(new File("E:/testnew${empname}.xml"), content);
}
catch (Throwable ex) {
log.info("What happened?", ex);
throw ex;
}
Instead of writing again to the disk and uploading again, how can I send the contents of string 'content' as part of request body? I have looked at many posts that talk about the input output streams but they are confusing. When I try to send just ${content} in body, the application throws following error:
HTTP Status 500 - Could not write JSON: Name is null (through reference chain: com.xxx.xxx.datafile.rest.DataFileResponse["validationStatus"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Name is null (through reference chain:
Appreciate your help.
Multipart POST requests which are being used for files upload are different from normal POST requests hence there no possibility to simply substitute the file with the generated in-memory string.
You need to replicate the request exactly as it would be send by JMeter or real browser and manually populate each part starting from defining boundary using the HTTP Header Manager and ending up with the creation of Content-Disposition and specify your file contents there.
A little hint: you don't need to generate/substitute values for each call, it is enough to replace them once and JMeter will substitute them on its own given you use __eval() and __FileToString() functions combination.
You can check out Testing REST API File Uploads in JMeter for an example of creation a relatively complex file upload request, in your case it will be easier but still tricky.

convert object stream to readable stream hapi

I am creating REST api with hapi and mongojs. I need to output large number of JSONs as API response. I am using following code. But getting error “Error: Stream must have a streams2 readable interface”.
handler: function(request, reply) {
reply(db.collection.find().pipe(JSONStream.stringify()));}
How do I convert mongojs object stream to readable stream?
I tried following code as well
var outputStream = db.collection.find().pipe(JSONStream.stringify());
reply(outputStream.pipe(new Readable().wrap(outputStream)));
but it doesn't show any data in output.