cancel
Showing results for 
Search instead for 
Did you mean: 

Upload BLOB through Handheld application

Former Member
0 Kudos

Hi,

I am developing NW Mobile Handheld application with 7.10 SP10 IDE. I want to upload an image and send it to DOE. I have created a model in DOE and imported the same in NWDS. The data type for the attachment attribute generated is BLOB as expected. My question is how do i create BLOB object so that i can fill the stream in it by reading a file. In laptop application i could see createBLOB() method in model instance to create BLOB object. But i couldnt see it in model class generated in PDA application.

Regards,

Dhana

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Dhana,

Here is the sample code:

public void onActionCreate (Event wdEvent) {

//@@begin onActionCreate(ServerEvent)

try {

AttahtstModel model = (AttahtstModel) OcaRoot.getInstance().getOcaModel(AttahtstModel.class);

AttachmentDataObjectAttachment element = model.createAttachmentDataObjectAttachment();

element.setAttachmentId(-1);

element.setAttachmentClob("X");

element.setAttachmentBlob("X");

element.setAttachmentClobActual("This is a new record");

BLOB blob = (BLOB) element.getAttachmentBlobActual();

InputStream is = blob.getBinaryStream();

String mobileHome = new File(Configuration.getInstallationDirectory()).getCanonicalPath();

String imageName = "image_new.jpg";

File imageFile = new File(mobileHome "
MobileApps
demo.sap.comattuiimplementation
Components
com.sap.demo.attui.wd.comp.attachmentcomp.AttachmentComp
"
imageName);

FileInputStream fis = new FileInputStream(imageFile);

blob.setBinaryStream(fis, imageFile.length());

OcaRoot.getInstance().commit();

wdContext.currentContextElement().nodeAttachmentDataObjectAttachment().bind(model.getAttachmentDataObjectAttachments());

wdContext.reload();

} catch (Exception e) {

e.printStackTrace();

}

//@@end

}

Thanks and Regards,

Suma

Former Member
0 Kudos

Hi Suma,

Thanks. It worked.

Regards,

Dhana

Answers (0)