Important! A new Community experience launched on September 26, 2017. Read more about it here or continue to Base Camp.
Voting: 
Vote up!
0 Votes
8 Replies

convert image to raw bytes for email attachment

ayou ixe on Feb 28, 2017 03:50 EST

Posted In
Vote up!
0 votes
Vote down!

Hi,

I would also like to clarify the step below:

http://docs.kony.com/konylibrary/visualizer/viz_api_dev_guide/content/sharefilesandroid.htm#Specify

Specifying the FileProvider in the Manifest Properties

I followed the steps to sharing files on android. I created an xml named filespath.xml with the following content:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<paths>
   <files-path path="images/" name="myimages"/>
</paths>

I added the following to the Application Tag Attributes:

<provider   android:name="android.support.v4.content.FileProvider"   android:authorities="com.bdo.pay.anyone.mobile.fileprovider"   android:exported="false"   android:grantUriPermissions="true">   <meta-data      android:name="android.support.FILE_PROVIDER_PATHS"      android:resource="@xml/filepaths" /> </provider>

I am getting an error when building the app.

[Fatal Error] :5:82: Element type "application" must be followed by either attribute specifications, ">" or "/>".

Please advise.

 

Replied by: Feb 28, 2017 22:46 EST
Vote up!
0 votes
Vote down!

I'm having trouble myself with the read() function: var imgAttach=new kony.io.File(fileLoc).read(); I'm getting the idea that function does not work or some conversion hast to be done.

Does it work when you just use imgRawBytes as the attachment?

Replied by: Mar 02, 2017 08:32 EST
Vote up!
0 votes
Vote down!

 

 

Replied by: Mar 02, 2017 08:44 EST
Vote up!
0 votes
Vote down!

Hi Roelof Koelewijn,

 

No, it doesn't work. imgRawBytes returns empty or null but I don't get why.

 frmMRCodeGen.imgSnap.image = imgSnapshot; 

This clearly works as the image is shown in the app but when I try to convert it using getImageAsRawBytes, it returns empty of null. I've tried using base64, rawBytes, but it still does not convert my image, either from the image widget or the image creates from snapshot, into rawbytes.

Replied by: Mar 02, 2017 21:41 EST
Vote up!
0 votes
Vote down!

Hi Roelof Koelewijn,

 

I tried your fix

var imgAttach=JSON.stringify(new kony.io.File(fileLoc).read());

It doesn't work for me. Still shows a toast "Can't attach empty file". I believe the root cause is the image conversion to raw bytes since it does not convert into raw bytes

Replied by: Mar 02, 2017 22:27 EST
Vote up!
0 votes
Vote down!

Maybe you could try:  var imgAttach = frmMRCodeGen.imgSnap.rawBytes

Replied by: Mar 03, 2017 01:13 EST
Vote up!
0 votes
Vote down!

I've already tried that. I also tried base64. I also tried kony.convertToBase64 and kony.convertToRawBytes.

Somehow, I've been finding some threads that say that only images taken using the Camera API can be converted into raw bytes. Namely this one, it stands out a lot.

http://community.kony.com/developer/forum/convert-image-src-base64

Replied by: Mar 03, 2017 04:08 EST
Vote up!
0 votes
Vote down!

Hi Kony,

Any update on this?

Replied by: Mar 15, 2017 01:15 EDT