How to send file using XMLHttpRequest? - xmlhttprequest

How to send file in QML. I tried something like:
var pathImage = "file:assets-library:/asset/asset.JPG%3Fid=0EEAFD08-5878-45D1-9045-025FD5CAB907&ext=JPG"
var request = new XMLHttpRequest();
var request_url = API_URL + '?method=postImage';
request.open('POST', request_url);
var params = "image=" + pathImage;
request.send(params);
But it doesn't send file.
How to send file in QML without C-code?

Related

can i send xhttp request using blogger tags like this

I have this
const xhttp = new XMLHttpRequest();
xhttp.open("GET",`https://www.googleapis.com/blogger/v3/blogs/ID/posts/bypath?path=/2022/02/never-give-up.html&key=KEY`, true);
xhttp.send();
xhttp.onload = function() {
let responseJSON = JSON.parse(this.responseText);
responseJSON.labels[0]==="html"
&&(MY-code);
}
its working fine but i want to do same thing with blogger tags like
<b:eval expr='data:xhttp = new XMLHttpRequest()'/>
<b:eval expr='data:xhttp.onload = function(){data:responseJSON = JSON.parse(this.responseText);}'/>
<b:eval expr='data:xhttp.open("GET","https://www.googleapis.com/blogger/v3/blogs/id/posts/bypath?path=/2022/02/never-give-up.html&key=KEY",true);}'/>
<b:eval expr='data:xhttp.send();}'/>
<b:if cond='data:responseJSON.labels[0]==="html"'>
//my-code
</b:if>
can i do this if posible
its not showing error but also not working

FTX API in Google Apps Script not authenticating

I've successfully connected to most other crypto exchanges but keep getting "success":false,"error":"Not logged in" when using FTX.
This is my code:
var host = 'https://ftx.com/api';
var endpoint ='/wallet/all_balances';
var url = host + endpoint;
var timestamp = ''+ new Date().getTime();
var payload = timestamp + 'GET' + endpoint+'';
var shaObj = new jsSHA("SHA-256", "BYTES");
shaObj.setHMACKey(secret, "BYTES");
shaObj.update(payload);
var signature = shaObj.getHMAC("HEX");
var options = {
method: 'get',
headers: {
'FTX-KEY': key,
'FTX-TS': timestamp,
'FTX-SIGN': signature
},
muteHTTPExceptions: 'true'
}
var jsondata = UrlFetchApp.fetch(url, options);
var data = JSON.parse(jsondata.getContentText());
Any help much appreciated!
Found the answer:
var host = 'https://ftx.com';
var endpoint ='/api/wallet/all_balances';

Image uploaded on dropbox does not have any content

I am using Dropbox api uploadAsync to upload an image which in itself is passed in raw data form from another POST request. The upload is successful in terms that there is a file now on dropbox. But when I access that file, it says it has no contents. Why is it uploading file without content? Here is what I have tried
MemoryStream memoryStream = new MemoryStream();
imageStream.Position = 0;
memoryStream.Position = 0;
imageStream.CopyTo(memoryStream);
var task = Task.Factory.StartNew(() => {
var dropboxClient = new DropboxClient(token);
var folder = "XYZ";
var fileName = "ABC";
var upload = dropboxClient.Files.UploadAsync(folder + "/" + fileName, Dropbox.Api.Files.WriteMode.Add.Instance, autorename:true, body: memoryStream);
upload.Wait();
});
task.Wait();
imageStream is the Stream which I get from a POST request. It has raw image data.
Any help would be appreciated

how to upload a file using autoit in protractor

I tried the code below but it isn't working. Can someone help me understand how to upload a file using autoit in protractor?
var path = require('path');
var file = "../Snaptrude/plans/"+filepath+"";
console.log('file path',file)
var filePath = path.resolve(__dirname, file);
// browser.sleep(3000);
element(by.css('input[type="file"]')).sendKeys(filePath);
var path = require('path');
var appRoot = require('app-root-path');
var uploadFile = appRoot + '/path of the file which you want to upload';
var deferred = protractor.promise.defer();
var control = element(by.xpath('you need to take the xpath of uploaded file'));
control.getText().then(function(text) {
if (text == 'filename') {
enter code hereconsole.log("success");
}
without using autoit you can upload the file using above way, if you are work on any web application.

Jsreport Malformed URI error when rendering Async

Since I am sending lots of data with the request, I have to use renderAsync to use POST. When the stream came back, I use the following JS code to open it
jsreport.renderAsync(request).then(function(arrayBuffer) {
window.open("data:application/pdf;base64," + arrayBuffer
)};);
But then the error showed. Is there alternative way to do it?
This seems to work
<script>
jsreport.renderAsync(request).then(function(response) {
var uInt8Array = new Uint8Array(response);
var i = uInt8Array.length;
var binaryString = new Array(i);
while (i--)
{
binaryString[i] = String.fromCharCode(uInt8Array[i]);
}
var data = binaryString.join('');
var base64 = window.btoa(data);
window.open("data:application/pdf;base64, " + base64);
})
</script>