Hello.
It´s possible convert a image to binary in Servoy?
I need send data to a web service and the image must be in binary.
Thanks
Servoy 7.4.3
function subirFotoServidor(jsfile, record){
plugins.file.streamFilesToServer(jsfile.getAbsolutePath(), "/fotos/" + record.md5);
var image = plugins.images.getImage(jsfile.getAbsolutePath());
image = image.resize(500,500);
var bytes = image.getData();
var tempFile = plugins.file.createTempFile("","");
plugins.file.writeFile(tempFile, bytes);
plugins.file.streamFilesToServer(tempFile, "/fotos/" + record.md5 + "." + "500x500");
plugins.file.deleteFile(tempFile);
return 1;
}
var image = plugins.images.getImage('d:/photo/image.jpg');
var bytes = image.getData();
var tempFile = plugins.file.createTempFile("","");
plugins.file.writeFile(tempFile, bytes);
var url='https://'+xxxxxxxxxxxx+'/api/images/products/10?';
var cliHttp = plugins.http.createNewHttpClient();
var postRequest = cliHttp.createPostRequest(url);
postRequest.addFile(null,tempFile);
response=postRequest.executeRequest();
postRequest.addFile(null,tempFile);
<?xml version="1.0" encoding="UTF-8"?>
<xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code>
<![CDATA[66]]>
</code>
<message>
<![CDATA[Unable to save this image]]>
</message>
</error>
</errors>
<html>
<body>
<form enctype="multipart/form-data" method="POST" action=
"https://xxxxxxxxxxxxxxxx/api/images/products/10">
<fieldset>
<legend>Add image for products No 1</legend>
<input type="file" name="image">
<input type="submit" value="Execute">
</fieldset>
</form>
</body>
</html>
var image = plugins.images.getImage(_ar.foto);
var bytes = image.getData();
var content=image.getContentType()
var tempFile = plugins.file.createTempFile("",".jpg");
var postRequest = cliHttp.createPostRequest(url);
postRequest.addHeader('enctype','multipart/form-data');
postRequest.addHeader('method','POST');
postRequest.addParameter('Content-Type',content);
postRequest.addFile('image',tempFile);
response=postRequest.executeRequest();
Return to Programming with Servoy
Users browsing this forum: No registered users and 11 guests