About attachments in flex viewer

6853
36
Jump to solution
04-21-2015 11:04 AM
EvelynHernandez
Occasional Contributor III

Hello,

I am developing an app that needs to add an attachment (pdf file) and save it in the arcgis db. Anyone knows how to do that?

My rest service has the attachment value in True, but idk why this code doesnt do it.

This is part of my code:

       myPropLayer.url = "myfeaturelayerurl";

myPropLayer.id = "NewEtaFeature";

  myPropLayer.addAttachment(1,byteArrayToProcess,"ElemetopPDF","pdf",new AsyncResponder(resultado,malresultado));

function resultado():void{

Alert.show("saved");

}

function malresultado():void{

Alert.show("not saved");

}

Mensaje editado por: Evelyn Hernandez. new Question about attachments

0 Kudos
36 Replies
EvelynHernandez
Occasional Contributor III

Thanks again Nigel , you will save my day again , i will wait for ur examples

0 Kudos
NigelDsouza
Occasional Contributor

HI evelyn,

Have a look at this example here Attachment Inspector—ArcGIS API for Flex | ArcGIS for Developers

This sample uses the queryAttachmentInfos method and its respective event. Try creating a sample and using it like this.

Regards,

Nigel.

0 Kudos
EvelynHernandez
Occasional Contributor III

Yeah i saw that already, but how im making a widget is not the same.

The widget needs to get all the attachment infos related with the objectid selected in a datagrid element.

There is a after picture and before picture as attachment for each objectid.

So i need to previsualize both pictures in a different canvas on the widget, one for each one.

And then, how i cannot update the pic, i need to delete it and then add a new one if i the user wanna change it.

Idk how to integrate those example to this code, this is what i have until now:

public function buscarCargarFotografias():void{  

  var arrayInfos:ArrayCollection = new ArrayCollection;  


  var objActividad:int= DataActividades.selectedItem['OBJECTID'];  

  myActividadLayer.queryAttachmentInfos(objActividad,new AsyncResponder(onResult,onFault));  

  function onResult(event:Object, token:Object=null):void{  

  var arry:Array = new Array(event.attachmentInfos);

  var attachmentInfo:AttachmentInfo = arry[0];
  var imageUrl:String = String(attachmentInfo.url);



  //var attachmentInfo:AttachmentInfo= arry[0];  
  var imageUrlAntes:String = imageUrl;  
  /*
  var attachmentInfo2:AttachmentInfo= arry[1];  
  var imageUrlDespues:String = attachmentInfo2.url;  
  */


  var imageAntes : Image = new Image();  

  imageAntes.source = imageUrlAntes;  
  imageAntes.scaleContent = true;  
  imageAntes.maintainAspectRatio =false;  
  imageAntes.percentWidth = 150;  
  imageAntes.percentHeight = 150;  

  pbMODAntes1.addChild(imageAntes);  

  /*
  var imageDespues : Image = new Image();  

  imageDespues.source = imageUrlDespues;  
  imageDespues.scaleContent = true;  
  imageDespues.maintainAspectRatio =false;  
  imageDespues.percentWidth = 150;  
  imageDespues.percentHeight = 150;  

  pbMODDespues1.addChild(imageDespues);  
  */

  }  
  function onFault(event:Object,token:Object=null):void{
  Alert.show("It is not doing anythingAnd i ");
  }

  }

If u can show me an example will be useful and thanks again for all ur help

0 Kudos
NigelDsouza
Occasional Contributor

Hi Evelyn,

I got it. All you have to do is change this line of code

  function onResult(event:Object, token:Object=null):void

to

  function onResult(event:Array, token:Object=null):void

then you will directly get the url like this

       var url:String = event[0].url;

Try this and let me know.

Regards,

Nigel. 

0 Kudos
EvelynHernandez
Occasional Contributor III

i will try it and i will tell u how is going! Thanks Nigel

EvelynHernandez
Occasional Contributor III

Yes, it works perfectly.

I will try to do the deleteAttachments getting the ID from the attachments that i have with certain objectid.

I guess i can obtain the attachmentid using something like queryAttachmentinfos and then getting in the event:array the event[0].id

is that correct?

0 Kudos
NigelDsouza
Occasional Contributor

Hi Evelyn,

Yup that's right.

0 Kudos