Thursday, March 29, 2012

Use Picup App to upload image to website from iPhone

To allow iPhone image uploads on the the classic, yes, I said, classic ASP site I was working I followed the following Picup App instructions posted at:

http://www.parorrey.com/blog/php-development/resolve-mobile-safari-greyed-out-file-field-issue-in-iphone-ipod-ipad-by-using-picup-app-to-upload-images/

For the most part, the instructions worked just fine. The only item I would add is that the blog post is not very clear in stating that the iPhone user must download the free Picup App onto their phone for the code that you write to work. It is mentioned in the comments.

It is also mentioned here: http://picupapp.com/best_practices.html

However, the image is posted rather than the words of the error so googling it might be hard to find. The error that indicates the app has not been installed is a generic window that says:
"Safari cannot open the page because the address is invalid"

I did change the code to work with my asp site. I could not get the document.observe to work. I think that is what the prototype.js file is for but it was no go.

Instead I put 'hardcoded' the body tag "class=iphone" and used the onLoad to call my loadMobile() function instead of using the document.observe:


function loadMobile(){

Picup.checkHash();
var element = document.getElementById('aid');
var x;

if (typeof(element) != 'undefined' && element != null)
x = element.value;

var url = escape('http://mysite.com/uploadContactPhotoI.asp?Assigneduserid=' + x);

<!-- Set some starter params -->
currentParams = {
'callbackURL' : url,
'referrername' : escape('mysite'),
'referrerfavicon' : escape('http://mysite.com/images/favicon.ico'),
'purpose' : escape('Select your photo for the our App.'),
'debug' : 'false',
'returnThumbnailDataURL': 'true',
'thumbnailSize' : '80'
};

Picup.convertFileInput($('attach1'), currentParams);
}



And the following is the code used on the callback page go pick up the values passed back by the Picup app hash url:
<SCRIPT TYPE="text/javascript">

var allVars = getHashUrlVars();

// Get all URL parameters
var imageURL = unescape(getHashUrlVars()['remoteImageURL']);
var success = getHashUrlVars()['status'];

function getHashUrlVars(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}

function onSubmitForm(){
var startIndex = 0;

startIndex = imageURL.indexOf('.com/');
startIndex = startIndex + 5;

var fileName = imageURL.substring(startIndex);

if(success.toUpperCase() != 'COMPLETE')
alert("We were unable to complete the request to upload the image, please try again.");
else
{

document.getElementById('fname').value = fileName;
document.getElementById('rurl').value = imageURL;
document.getElementById('uploadedImg').src = imageURL;

}
}

function showImage(){

if(typeof(imageURL) != "undefined"){

if(document.getElementById('uploadedImg') != null)
{
document.getElementById('uploadedImg').src = imageURL;
document.getElementById('uploadedImg').style.display="block";
document.getElementById('uploadedImg').style.visibility="visible";
document.UpdateContactPhoto.action = "uploadContactPhotoI.asp?imageUrl=" + imageURL;
}
}
}

</script>

10 comments:

  1. Is there any way I could get both the index page and the upload page showing where element id's and other code is actually used? I am unable to get this to work properly. I have a submit page where Name, Last, Phone, ect.. and the image is to be added to the first php page. Then submitted to a upload php script. I feel that my problem is the item name values but honestly I have no clue. Your script has got me closer than I have been in days. Thanks in advanced no matter the answer received.

    ReplyDelete
  2. So how far are you able to get? Do you see the Picapp open and can select a photo? Or do you not get that far?

    ReplyDelete
  3. Yeah. The srript works perfectly on a regular pc. Also the mobile script detects mobile when using my iPad and loads picup script. I can add a photo with picup, getting the url my url.php#status=Complete&picID=p'somenumber'&remoteImageURL=http with escape values and the image url from imgur. Your script does parse imageURL. Because I tested it with
    document.write(imageURL);
    and viewed after a refresh of the first page of course. But how do I get that info to my actual upload.php script? I did try putting the script on the upload.php after setting my callbackURL to upload.php and it parse right away using the same document.write(imageURL) but I am still not sure how to get that info actually in my form along with the Name, Last Name, Phone, ect.. I feel like my brain is scrambled right now.

    ReplyDelete
  4. if you are wanting to get the data elements from the inital page, you could put it in the session, pass it in querys tring, grab it out of the POST like: $to = $_POST['to'];

    ReplyDelete
  5. You are awesome. But maybe I'm to much of a newbie to be trying to use this script because some of that I am familiar with and some not. Maybe I should buy the script picup has for 15 bucks and pray its what I need. I have done things similar in the past but for some reason the app in the mix has got me mixed up. All I need to do is add people to fellowship one with an image. Ipad!!!! lol. Any way. I don't want to bother you with this any more. Thank you so much for your help. I hope you have a blessed day.

    ReplyDelete
  6. No problem. I can send u my files. What is your email. I will delete it from the blot once we r done. Do not pay the money u can do it!!!

    ReplyDelete
  7. hi, is it possible to upload a pdf from iBooks iPhone/iPad application to a web site? (in place of photo application in picup app). Is there any way to get the script upload.php ? thanks in advanced

    ReplyDelete
  8. off the top of my head, i can only recall images being allowed.

    ReplyDelete
  9. Hi, I thnk this can be useful! I'm creating an app where i need to take photos an upload them to the server. So i guess i need to call urlForOptions() at some place. Could I altso get to see the index page and the upload page?

    Right now the script wont load properly. I think it is because i dont send the right variables.
    When i try to take a photo and upload it, Picup says that "the upload was not compleated".

    Thanks for the post.

    ReplyDelete
  10. This comment has been removed by a blog administrator.

    ReplyDelete