Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to pass image to server?

I have an SL3 application that needs to be able to pass an image to the server, and then the server will generate a PDF file with the image in it, and display it to the user.

What I already have in place are the following:

(1) Code to convert image to byte array (2) Code to generate PDF file with image

The main problem that I am running into is the following:

In order to bypass the pop-up blocker, which is a requirement for my application, I am using the following code:

var button = new NavigationButton();

button.NavigateUri = new Uri("http://localhost:3616/PrintReport.aspx?ReportIndex=11&ActionType=Get&ReportIdentifier=" + reportIdentifier.ToString() + "");

button.TargetName = "_blank";

button.PerformClick();

Initially, I would pass the image to a WCF web service (as a byte array), and then "navigate" to the ASP.NET page that would display the report. However, if I do this, then I can not use my custom HyperlinkButton class, and, certain browsers, including Safari, will block a new window from opening up. Therefore, it appears that the only option is to use the HyperlinkButton class.

What I need to be able to do is to somehow pass the image, as a byte array or some other data type, to the server, such that it can temporarily store the image, even if it is in a server variable, and then immediately retrieve it when I navigate to the PrintReport.aspx page.

If I upload the image to an ASP.NET form and then use the HyperlinkButton class to navigate to the PrintReport page, it doesn't work, as the app navigates to the PrintReport page before the system has finished uploading the image. I can't pass it to a web service, as that would require that I navigate to the PrintReport.aspx page in the callback code of the web method that I would be passing the image to, and the HyperlinkButton will not allow that, based on security rules.

Any help or ideas would be appreciated.

Thanks.

Chris

like image 578
Chris Avatar asked May 24 '10 12:05

Chris


People also ask

How do I send pictures to a server?

To Upload The Image In Server it takes only three steps:- php $host = 'localhost'; $user = 'root'; $pass = ' '; mysql_connect($host, $user, $pass); mysql_select_db('demo'); $upload_image=$_FILES[" myimage "][ "name" ]; $folder="/xampp/htdocs/images/"; move_uploaded_file($_FILES[" myimage "][" tmp_name "], "$folder".

Can you send images via API?

When we need to send an Image file to an API request there are many options. I will explain some of those methods to send an Image by using the postman. Option 1: Direct File Upload , From this method you can select form-data and set the type to file.

How do I upload pictures to my android?

On your Android phone or tablet, open the Google Drive app. Tap Upload. Find and tap the files you want to upload. View uploaded files in My Drive until you move them.


1 Answers

Is sounds like your problem is less to do with the image upload, and more to do with using only one click to upload and navigate to the page the report is displayed on, if that is the case, then handling the image upload on the reports page itself might be the way to go.

Upload files with HTTPWebrequest (multipart/form-data)

shows how to upload to a standard aspx page

As for getting the webservice approach working, I'd say the piece of the jigsaw you're missing here is WCF ASP compatibility mode.

This enables you to access the httpcontext in a wcf service. The catch of course is that you're coupling your service to ASP....

Take a look here http://blogs.msdn.com/wenlong/archive/2006/01/23/516041.aspx for more details on ASP compatibility mode.

Your process then becomes:

Upload to Webservice -> add to cache

Navigate to page -> Retreive from cache

hope one of these suggestions helps

if not, get back to me!

like image 113
stevenrcfox Avatar answered Sep 22 '22 00:09

stevenrcfox