Upload from Android

94 views
Skip to first unread message

Xeyos

unread,
Mar 2, 2011, 4:50:55 PM3/2/11
to phonegap
Guys I'm trying to upload photos to Flickr from Android.
I can access the gallery and take a picture but I'm afraid of making
mistakes that should be sending in POST.
This is my code:

<!DOCTYPE html>
<html>
<head>
<title>ViewFlickr</title>
<meta charset="utf-8">
<link href="style.css" rel="stylesheet" type="text/css"
media="screen" />
<script type="text/javascript" charset="utf-8" src="phonegap.js"></
script>
<script src="http://code.jquery.com/jquery-latest.js" type="text/
javascript"></script>
<script src="md5.js" type="text/javascript"></script>
<script type="text/javascript">
var pictureSource;
var destinationType;

function onLoad() {
document.addEventListener("deviceready",onDeviceReady,false);
}


function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}



function onPhotoURISuccess(imageURI) {
var baseUrl = "http://api.flickr.com/services/upload/?";
var apiKey = "XXXXXXXX";
var secret = "XXXXXXX";
var hash = $.md5(secret + "api_key" + apiKey + "auth_token" +
window.localStorage.getItem("token"));
var url = baseUrl + "api_key=" + apiKey + "&auth_token=" +
window.localStorage.getItem("token") + "&api_sig=" + hash;
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName="image.jpg";
options.mimeType="image/jpeg";
var ft = new FileTransfer();
ft.upload(imageURI, url, win,
fail, options);
window.location="upload.html";
}

function capturePhoto() {
navigator.camera.getPicture(onPhotoURISuccess, onFail,
{ quality: 50 });
}


function capturePhotoEdit() {
navigator.camera.getPicture(onPhotoURISuccess, onFail,
{ quality: 20, allowEdit: true });
}


function getPhoto(source) {
navigator.camera.getPicture(onPhotoURISuccess, onFail,
{ quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}


function onFail(mesage) {
alert('Failed because: ' + message);
}

function win(evt) {

console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}

function fail(evt) {
alert("An error has occurred: Code = " = error.code);
}

</script>
</head>
<body onload="onLoad()">
<button onclick="capturePhoto();">Capture Photo</button> <br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo
Library</button><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From
Photo Album</button><br>
</body>
</html>

Xeyos

unread,
Mar 2, 2011, 5:21:18 PM3/2/11
to phonegap

Sorry, my mistake.
I have to create a form like this, but I need to download the file
from the gallery because obviously the input file does not work. is it
possible?

<form method="post" action="http://api.flickr.com/services/upload/">
Photo: <input type="file" name="photo" id="photo"/>
Title: <input type="text" name="title" id="title"/>
<input type="hidden" name="api_key" id="api_key" value="API Key goes
here"/>
<input type="hidden" name="auth_token" id="auth_token" value="Put Auth
Token here"/>
<input type="hidden" name="api_sig" id="api_sig" value="xxxxx"/>
<input type="submit" value="Upload"/>
</form>

Xeyos

unread,
Mar 3, 2011, 5:49:54 AM3/3/11
to phonegap
I tried it but nothing ...
function onPhotoURISuccess(imageURI) {
var baseUrl = "http://api.flickr.com/services/upload/";
var apiKey = "xxxxxxxxxxxx";
var secret = "xxxxxxxxx";
var hash = $.md5(secret + "api_key" + apiKey + "auth_token" +
window.localStorage.getItem("token"));
//var url = baseUrl + "api_key=" + apiKey + "&auth_token=" +
window.localStorage.getItem("token") + "&api_sig=" + hash;
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName="image.jpg";
options.mimeType="image/jpeg";

var params = new Object();
params.api_key = apikey;
params.auth_token=window.localStorage.getItem("token");
params.api_sig = hash;

options.params = params;

var ft = new FileTransfer();
ft.upload(imageURI, "http://api.flickr.com/services/upload/",
win,
fail, options);
window.location="upload.html";
}

Simon MacDonald

unread,
Mar 3, 2011, 3:13:26 PM3/3/11
to phon...@googlegroups.com
I dont' know much about the Flickr API but what are you getting back
as a response? The upload API
(http://www.flickr.com/services/api/upload.api.html) returns some
descriptive error codes.

Simon Mac Donald
http://hi.im/simonmacdonald

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com
>

Xeyos

unread,
Mar 3, 2011, 6:17:57 PM3/3/11
to phonegap
how do I view it with the emulator? But the last code I wrote is
correct?

On 3 Mar, 21:13, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> I dont 'so molto circa l'API Flickr ma che cosa stai tornandocome una risposta?Il caricamento API(http://www.flickr.com/services/api/upload.api.html) restituisce alcunicodici di errore descrittivo.
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald
>
>
>
>
>
>
>
> On Thu, Mar 3, 2011 alle 05:49, Xeyos <xeyo...@ hotmail.it> ha scritto:> Ho provato ma niente ...> OnPhotoURISuccess funzione (imageURI) {> Baseurl var = "http://api.flickr.com/services/upload/";> ApiKey var = "xxxxxxxxxxxx";> Segreto var = "xxxxxxxxx";> Hash var = $. Md5 (segreto + "api_key" + apiKey + "auth_token" +> Window.localStorage.getItem ("token"));> / / Url = var baseurl + "api_key =" + apiKey + "& auth_token =" +> Window.localStorage.getItem ("token") + "& api_sig =" + hash;> Opzioni FileUploadOptions var = new Date ();> Options.fileKey = "file";options.fileName> = "immagine.jpg";options.mimeType> = "image / jpeg";
>
> > Params var = new Object ();> = Params.api_key apikey;> Window.localStorage.getItem params.auth_token = ("token");> Params.api_sig = hash;
>
> > Options.params = params;
>
> > Ft FileTransfer var = new Date ();> Ft.upload (imageURI, "http://api.flickr.com/services/upload/",> Vittoria,> Falliscono, opzioni);window.location> = "upload.html";>}
>
> > Il 2 Mar, 23:21, Xeyos xeyo <...@ hotmail.it> ha scritto:>> Scusa, ho sbagliato io.>> Ho per creare un modulo come questo, ma ho bisogno di scaricare il file>> Dalla galleria perché evidentemente il file di input non funziona.è>> Possibile?
>
> >> <Form method = post "azione" = "http://api.flickr.com/services/upload/">>> Foto: <input type="file" name="photo" id="photo"/>>> Titolo: <input type="text" name="title" id="title"/>>> Tipo <input name = "nascosto" = "api_key" id = valore "api_key" = "API Key va>> Qui "/>>> Tipo <input name = "hidden" id = "auth_token" = valore "auth_token" = "Put Auth>> Token qui "/>>> <input Type="hidden" name="api_sig" id="api_sig" value="xxxxx"/>>> <input Type="submit" value="Upload"/>>> </ Form>>> Il 2 Mar, 22:50, <xeyo Xeyos...@> hotmail.it ha scritto:
>
> >> Ragazzi> Sto cercando di caricare le foto su Flickr da Android.>>> Non posso accedere alla galleria e scattare una foto ma ho paura di fare>> Errori> che dovrebbe essere l'invio in POST.>>> Questo è il mio codice:
>
> >>> <!> DOCTYPE html>>> <html>>>> <head>>>> <title> ViewFlickr </ title>>>> <meta Charset="utf-8">>>> Href <link rel = "style.css" = "stylesheet" type = "text / css">>> Media = "screen" />>>> <script Type="text/javascript" charset="utf-8" src="phonegap.js"> </>>> Script>>>> <Script src = "http://code.jquery.com/jquery-latest.jstipo "=" text />>> Javascript "> </ script>>> <script> Src="md5.js" type="text/javascript"> </ script>>>> <script Type="text/javascript">>>> Var pictureSource;>>> Var destinationType;
>
> >>> OnLoad function () {>>> Document.addEventListener ("deviceready", onDeviceReady, false);>>>}
>
> >>> OnDeviceReady function () {>>> = PictureSource navigator.camera.PictureSourceType;>>> = DestinationType navigator.camera.DestinationType;>>>}
>
> >> OnPhotoURISuccess funzione> (imageURI) {>>> Baseurl var = "http://api.flickr.com/services/upload/?";>>> ApiKey var = "XXXXXXXX";>>> Segreto var = "XXXXXXX";>> Hash> var = $. Md5 (segreto + "api_key" + apiKey + "auth_token" +>>> Window.localStorage.getItem ("token"));>>> URL var = baseurl + "api_key =" + apiKey + "& auth_token =" +>>> Window.localStorage.getItem ("token") + "& api_sig =" + hash;>> Opzioni var> = FileUploadOptions new ();>>> Options.fileKey = "file";>>> Options.fileName = "immagine.jpg";>>> Options.mimeType = "image / jpeg";>>> FT var = FileTransfer new ();>>> Ft.upload (imageURI, url, vincere,>>> Fallire, opzioni);>>> Window.location = "upload.html";>>>}
>
> >>> Funzione capturePhoto () {>>> Navigator.camera.getPicture (onPhotoURISuccess, onFail,>>> {Qualità: 50});>>>}
>
> >>> CapturePhotoEdit function () {>>> Navigator.camera.getPicture (onPhotoURISuccess, onFail,>>> {Qualità: 20, allowEdit: true});>>>}
>
> >>> Funzione getPhoto (fonte) {>>> Navigator.camera.getPicture (onPhotoURISuccess, onFail,>>> {Qualità: 50,>>> DestinationType: destinationType.FILE_URI,>>> SourceType: fonte});>>>}
>
> >>> OnFail funzione (mesage) {>>> Alert ('non riuscita perché:' + messaggio);>>>}
>
> >>> Funzione vincere (evt) {
>
> >>> Console.log ("Codice =" + r.responseCode);>>> Console.log ("Risposta =" + r.response);>>> Console.log ("Inviati =" + r.bytesSent);>>>}
>
> >>> Funzione fail (evt) {>> Allarme> ("è verificato un errore: Code =" = error.code);>>>}
>
> >>> </ Script>>>> </ Head>>>> <body Onload="onLoad()">>>> <button Onclick="capturePhoto();"> Photo Capture </ button> <br>>>> Onclick="getPhoto(pictureSource.PHOTOLIBRARY);"> <button da Photo>>> Biblioteca </ button> <br>>>> Da onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);"> <button>>> Album fotografico </ button> <br>>>> </ Body>>>> </ Html>
>
> > -> Hai ricevuto questo messaggio perché sei iscritto a GoogleGruppi> gruppo "PhoneGap".> Per postare in questo gruppo, invia un'email a phon...@googlegroups.com> Per annullare l'iscrizione a questo gruppo, invia un'email a> PhoneGap + unsub...@googlegroups.com> Per maggiori opzioni, visita questo gruppo all'indirizzo>http://groups.google.com/group/phonegap?hl=en?hl=en
>
> > Per maggiori informazioni su PhoneGap o per scaricare il codice di andare awww.phonegap.com

Simon MacDonald

unread,
Mar 3, 2011, 8:58:21 PM3/3/11
to phon...@googlegroups.com
Your code looks okay but again I haven't tried to upload to flickr.
Run "adb logcat" to get the logs when you are running your test in the
simulator to get more info.

2011/3/3 Xeyos <xey...@hotmail.it>:

Xeyos

unread,
Mar 4, 2011, 6:24:02 AM3/4/11
to phonegap
the error is
No photo specified
The photo required argument was missing.
does not send the photo
On 4 Mar, 02:58, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> Your code looks okay but again I haven't tried to upload to flickr.
> Run "adb logcat" to get the logs when you are running your test in the
> simulator to get more info.
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald
>
> 2011/3/3 Xeyos <xeyo...@hotmail.it>:

Simon MacDonald

unread,
Mar 4, 2011, 9:35:10 AM3/4/11
to phon...@googlegroups.com
Yeah, I'm not 100% on this but try changing:

options.fileKey="file";

to:

options.fileKey="photo";

That looks to be the correct parameter based on the Flickr API docs.
Let me know if this works. I'm interested in posting to Flickr for a
project I'm working on.

Thanks...

2011/3/4 Xeyos <xey...@hotmail.it>:

Xeyos

unread,
Mar 4, 2011, 7:14:57 PM3/4/11
to phonegap
It works, I made a simple mistake and I could not fix it. Thank you,
for me it's important to have resolved.

On 4 Mar, 15:35, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> Yeah, I'm not 100% on this but try changing:
>
> options.fileKey="file";
>
> to:
>
> options.fileKey="photo";
>
> That looks to be the correct parameter based on the Flickr API docs.
> Let me know if this works.  I'm interested in posting to Flickr for a
> project I'm working on.
>
> Thanks...
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald
>
> 2011/3/4 Xeyos <xeyo...@hotmail.it>:

Xeyos

unread,
Mar 5, 2011, 10:01:39 AM3/5/11
to phonegap
there's only one problem, if successful the function WIN fails.

Xeyos

unread,
Mar 5, 2011, 11:36:17 AM3/5/11
to phonegap
The upload after the function capturePhoto does not work. Loading
after the photograph is probably different
Reply all
Reply to author
Forward
0 new messages