About attachments in flex viewer

6847
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
1 Solution

Accepted Solutions
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. 

View solution in original post

0 Kudos
36 Replies
NigelDsouza
Occasional Contributor

Hi Evelyn,

Your need to provide a valid objectid when you add attachments.

What error are your getting?

Also your resultado() and malresultado() methods need to have events passed as parameter which seems to be missing.

Regards,

Nigel.

0 Kudos
EvelynHernandez
Occasional Contributor III

Do u have any example where u  do that ?

It will be useful  for me

Thanks!!

0 Kudos
NigelDsouza
Occasional Contributor

Hi Evelyn,

Just correct your code with the following and see if it works.

resultado(event:AttachmentEvent) and malresultado(fault:FaultEvent).

Regards,

Nigel.

0 Kudos
EvelynHernandez
Occasional Contributor III

It doesnt work.

Do u have any complete example using that? I already read the sample in the developers webpage but idk why it doesnt work for me. Im not using the attachment inspector object.

0 Kudos
EvelynHernandez
Occasional Contributor III

I need some help, im stuck on this.

I have to save a pdf file or image file in the arcgis db and idk how to do it through a widget. Theres no code example to try and seems nobody has done yet.

I have been trying with the attch inspector but it doesnt work. Anyone can give any example ?

Thanks for ur help.

I have this code but it doesnt work.

public function savePDF(byteArr:ByteArray):void
  {
  
  var myfeaturelayer:FeatureLayer = new FeatureLayer;
  myfeaturelayer.url = "http:...../PMGD/FeatureServer/8";

  myfeaturelayer.id = "NewEtaFeature";
  
  myfeaturelayer.addAttachment(1,byteArr,"ElementoPDF", null,new AsyncResponder(resultado,malresultado));


  function resultado(event:AttachmentEvent):void{
  Alert.show("saved");

  }
  function malresultado(fault:FaultEvent):void{
  Alert.show("not saved");
  }


  }
0 Kudos
NigelDsouza
Occasional Contributor

When you debug this code what error do you get? Also check if your feature service has attachments enabled.

0 Kudos
EvelynHernandez
Occasional Contributor III

i cannot debug my app, so when i execute the code i dont get any responde (not true or false)

0 Kudos
NigelDsouza
Occasional Contributor

Everything seems to be fine with the code you have written. you can also check the "layer details" property of

the feature layer to check whether attachments have been enabled on your featurelayer.

var layerDetails:LayerDetails = myfeaturelayer.layerDetails

if(layerDetails.hasAttachments)

{

       Alert.show("attachments enabled");

      savePDF(byteArr);

}

else

{

     Alert.show("Please enable attachments");

}

One more thing is, you could try passing the "content type" as a parameter instead of passing null..

  myfeaturelayer.addAttachment(1,byteArr,"ElementoPDF", "pdf",new AsyncResponder(resultado,malresultado));

And like i said earlier you need to pass a valid object_id.

And here's a small tip for to get your debugger working.

Assuming that you are working with flash builder it is necessary that the debugger version installed is the same as the version of flash player in your browser.

  1. First check the version of flash player running your browser. Navigate to the following link to check the version Flash Player Help

          if it is an outdated version I recommend you update it.

2. Once you've got your flash player version updated/installed navigate to the following link to download the debugger

     Adobe Flash Player - Downloads

Select the appropriate debugger and click install.

3. Then insert some breakpoints,run your app in debug mode and i think your off..

Actually its really hard to suggest any solution cause your code seems fine... i guess through a debug session you might be able to track some errors..or maybe some section of code that isnt getting called.. hence the expected output is void.

Hope this helps.. do get back,...

Regards,

Nigel.

0 Kudos
EvelynHernandez
Occasional Contributor III

The code that u send me doesnt do anything, but in my rest srv i have the has attachment in true.

Im downloading the debugger.

And i also tried putting the "PDF" in the content type but still doesnt work.

Idk what more i should do...

0 Kudos