Performing post request with content-type multipart/form-data (for binary file)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Performing post request with content-type multipart/form-data (for binary file)
Hi,
in a script test, I would like to use the send method to send a binary file, namely a desktop screenshot, formatted in the content type "multipart/form-data". According to the JavaScript code example for the CreatePostRequest Method I wrote down the following:
function httpPostRequest() { var address = "https://example.com/receiver"; // Define the request body FormData-Object var requestBody = new FormData(Sys.Desktop.Picture()); // Create the aqHttpRequest object var aqHttpRequest = aqHttp.CreatePostRequest(address, "", ""); // Specify the Content-Type header value aqHttpRequest.SetHeader("Content-Type", "multipart/form-data"); // Send the request, create the aqHttpResponse object var aqHttpResponse = aqHttpRequest.Send(requestBody); // Check the response: Log.Message(aqHttpResponse.StatusCode); // A status code Log.Message(aqHttpResponse.Text); // A body }
But the JavaScript object FormData, which is to be generated in this code, is apparently not supported by TestComplete. The error "ReferenceError: FormData is not defined" appears. Or what am I doing wrong?
Is there any other way? Or do I have to build my own function to format the binary code according to the standard (see here)?
Thanks in advance for any hint and best regards
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Then, considering that TC 12.4 and up supports external project files (https://support.smartbear.com/testcomplete/docs/general-info/version-history/features-added-to-ver-1...), I would stick to Helen's suggestion: add curl files to some subfolder of your test project so that they are deployed to CBT and use it (curl) to send the screenshot.
https://support.smartbear.com/testcomplete/docs/reference/program-objects/picture/savetofile.html describes how to save the screenshot to the file.
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Alex,
> Then, considering that TC 12.4 and up supports external project files (https://support.smartbear.com/testcomplete/docs/general-info/version-history/features-added-to-ver-1...), I would stick to Helen's suggestion: add curl files to some subfolder of your test project so that they are deployed to CBT and use it (curl) to send the screenshot.
That almost sounds too good to be true. In this respect, I would understand the Release Notes to mean that it is possible to use your stored test data in this way, for example. Don't you think SMARTBEAR would have made it even clearer if Windows applications could suddenly be run on cloud machines? Which keyword operation or scripting method would I use to verify this approach? Is there a way to do this that works without the TestComplete Desktop module, i. e. only with the Web module?
Edit 1: As I just saw, Helen recommended in her post above to call curl with the WshShell.run method. Should this work without a Desktop module?
Edit 2: And once again in order to double-check: Is there no way to extract these original, unaltered, i. e. not encoded, non-human readable control characters that make up my screenshot graphics file, so that I can concatenate the data myself in the required multipart/form-data format? The rest of the Javascript needed for this task I have finished long ago, and of course it works - only this darned binary data is missing.
Thanks + best regards
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
> if Windows applications could suddenly be run on cloud machines?
Considering that your tests are running under TestExecute on the cloud machines, it is my expectation that some Windows environment is provided for TestExecute and thus, processes that are spawned from the test must be able to run in this environment.
The simplest check, probably, would be to copy some file into some subfolder of the test project and add a test (code or keyword) that will check if the file exists in this subfolder. Deploy and run this test into CBT and check if the file was found.
> the WshShell.run method. Should this work without a Desktop module?
Not sure, you should check. But in the worst case, WshShell is just a wrapper and you always should be able to use native JScript's
var objShell = new ActiveXObject("Wscript.Shell"); objShell.exec("curl ...");
> Is there no way to extract these original, unaltered, i. e. not encoded, non-human readable control characters that make up my screenshot graphics file
Try ADODB.Stream:
http://www.motobit.com/tips/detpg_post-binary-data-url/
http://www.motobit.com/tips/detpg_read-write-binary-files/
/Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wow, it works with curl, even on CrossBrowserTesting, brilliant! So at least with our TestComplete ProBundle license (i. e. including desktop module).
For now, thank you both for your expert advice!! I had already encountered curl during my research on multipart/form-data content type, but I didn't think it was possible that this could work so easily on CBT and therefore discarded it too quickly. Really great!
Thanks + best regards!

- « Previous
-
- 1
- 2
- Next »
- « Previous
-
- 1
- 2
- Next »