D
D
Deodatuss2016-09-06 09:28:32
Apache Flex
Deodatuss, 2016-09-06 09:28:32

How to send a FileReferense with parameters to the server in Flash(Flex) and get a response?

Hello. In general, there was a need to build one little thing on Flash (Flex). It's just a button, when you click on which the user selects a file, this file is sent to the server with additional parameters like userID and in response receives a link to this file. In general, I received the file through FileReference.browse(), but I don’t know how to send it now with parameters, and even get an answer right away, I tried a bunch of everything. Maybe someone is familiar with Flash (Flex) more than my one day. Thank you.
UPD:
Just send a file with parameters, it turns out:

var request:URLRequest = new URLRequest("http://192.168.0.104:7080/uploadfile");
  var variables:URLVariables = new URLVariables();
  var header:URLRequestHeader = new URLRequestHeader( "enctype", "multipart/form-data" );
  request.requestHeaders.push(header);
  equest.method = URLRequestMethod.POST;
  variables.user = "Some user";
  request.data = variables;
  file.upload(request, 'file');

Question how to get an answer
UPD:
Found events for FileReference , namely complete and uploadCompleteData. The first should work just with a 200 response status, and the second when receiving data from the server. The first event fires, but there is no data there (and should not be, as I understand it), but the second stupidly does not work at all, although I send the data. I googled, in general, this is a common mistake of the flash itself =\ I don’t know what to do. Are there other options or workarounds? Making another request after the complete event somehow doesn't smell very good.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
illuzor, 2016-09-06
@iLLuzor

Strangely, the DataEvent.UPLOAD_COMPLETE_DATA event has always worked in my practice.
Is there a possibility that the error is on the server side?
If not, you can try sending via URLLoader

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question