SilverHoodCorp / gdata-java-client

Automatically exported from code.google.com/p/gdata-java-client
Apache License 2.0
0 stars 0 forks source link

Downloading a file from google docs is working but uploading file to google docs site gives Error, in Android #242

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.login into google docs using 
DocsService.setUserCredentials(username,password)
2.after login successful try to upload a file using following method
3.
public static DocumentListEntry uploadFile( String filepath, String title ) 
throws IOException, ServiceException
    {
        File file = new File( filepath );
        DocumentListEntry newDocument = new DocumentListEntry();
        String mimeType = DocumentListEntry.MediaType.fromFileName( 
file.getName() ).getMimeType();
        newDocument.setFile( new File( filepath ), mimeType );
        newDocument.setTitle( new PlainTextConstruct( title ) );
        System.out.println( "*** return" );
        return service.insert( new URL( 
"http://docs.google.com/feeds/documents/private/full/" ), newDocument );
    }

What is the expected output? What do you see instead?

file should get uploaded on google docs site, but it gives error on return 
service.insert... line.

What version of the product are you using? On what operating system?
I am using 1.0 version with external .jar files - gdata-docs-1.0 and gdata-
docs-meta 1.0.  I use linux(ubuntu) operating system.

Please provide any additional information below.

the same function for uploading a file is working when run in a java 
application. but when used in an Android application it gives following 
error.
(downloading a file to android device works properly)

02-24 10:50:48.331: ERROR/dalvikvm(193): Could not find method 
javax.activation.DataHandler.getName, referenced from method 
javax.mail.internet.MimeUtility.getEncoding
02-24 10:50:48.331: WARN/dalvikvm(193): VFY: unable to resolve virtual 
method 9950: Ljavax/activation/DataHandler;.getName ()Ljava/lang/String;
02-24 10:50:48.341: WARN/dalvikvm(193): VFY:  rejecting opcode 0x6e at 
0x0004
02-24 10:50:48.341: WARN/dalvikvm(193): VFY:  rejected 
Ljavax/mail/internet/MimeUtility;.getEncoding 
(Ljavax/activation/DataHandler;)Ljava/lang/String;
02-24 10:50:48.378: WARN/dalvikvm(193): Verifier rejected class 
Ljavax/mail/internet/MimeUtility;
02-24 10:50:48.402: DEBUG/AndroidRuntime(193): Shutting down VM
02-24 10:50:48.402: WARN/dalvikvm(193): threadid=3: thread exiting with 
uncaught exception (group=0x4001aa28)
02-24 10:50:48.412: ERROR/AndroidRuntime(193): Uncaught handler: thread 
main exiting due to uncaught exception
02-24 10:50:48.455: ERROR/AndroidRuntime(193): java.lang.VerifyError: 
javax.mail.internet.MimeUtility
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
javax.mail.internet.ParameterList.quote(ParameterList.java:649)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
javax.mail.internet.ParameterList.access$200(ParameterList.java:71)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
javax.mail.internet.ParameterList$ToStringBuffer.addNV(ParameterList.java:6
17)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
javax.mail.internet.ParameterList.toString(ParameterList.java:598)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
javax.mail.internet.ContentType.toString(ContentType.java:217)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
javax.mail.internet.MimeMultipart.<init>(MimeMultipart.java:178)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
com.google.gdata.data.media.MediaMultipart.<init>(Unknown Source)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
com.google.gdata.client.media.MediaService.insert(Unknown Source)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
com.geodesic.androidim.util.GDocsUploadDownload.uploadFile(GDocsUploadDownl
oad.java:123)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
com.geodesic.androidim.util.GDocsUploadDownload.login(GDocsUploadDownload.j
ava:81)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
com.geodesic.androidim.ui.ArchiveActivity.onCreate(ArchiveActivity.java:88)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
android.app.ActivityThread.access$2100(ActivityThread.java:116)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
android.os.Handler.dispatchMessage(Handler.java:99)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
android.os.Looper.loop(Looper.java:123)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
android.app.ActivityThread.main(ActivityThread.java:4203)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
java.lang.reflect.Method.invokeNative(Native Method)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
java.lang.reflect.Method.invoke(Method.java:521)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
791)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
02-24 10:50:48.455: ERROR/AndroidRuntime(193):     at 
dalvik.system.NativeStart.main(Native Method)
02-24 10:50:48.461: INFO/Process(52): Sending signal. PID: 193 SIG: 3

Original issue reported on code.google.com by mundhe.a...@gmail.com on 24 Feb 2010 at 6:00

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thanks for your feedback mundhe.abhijeet.

Since you are developing an Android application, I strongly recommend you use 
the version 
2.1 alpha client instead.  The problem with using the version 1 client in this 
case is that 
it indirectly depends on the javax.activation package.  This package is 
included in the 
regular Java VM, but not in android.jar.  On the other hand, in the version 
2.1-alpha 
client, media upload is done in a way that is compatible with android.jar.  
There is 
actually an example of it in:

http://code.google.com/p/gdata-java-client/source/browse/tags/2.1.0-
alpha/sample/picasa/picasa-atom-android-
sample/src/com/google/api/data/sample/picasa/PicasaBasicAtomAndroidSample.java

Please try it, and let me know if you run into any problems.

Original comment by yanivin...@gmail.com on 9 Apr 2010 at 1:51

GoogleCodeExporter commented 9 years ago
Hi all!
I tried using the gcode-2.1.0-alpha.jar and it works fine. My problem is that I 
do
not have a 2.1 device and I cannot create a google account on emulator.
Is there an easier way to login to google, without using AccountManager? It 
would be
great if I could just specify the URL with username and password.

Thanks

Original comment by bgaborc...@gmail.com on 16 May 2010 at 5:30

GoogleCodeExporter commented 9 years ago
Excellent question.   Please take a look at my response at this e-mail thread: 

http://groups.google.com/group/gdata-java-client/browse_thread/thread/b297a7b652
133d22

Original comment by yanivin...@gmail.com on 16 May 2010 at 8:08

GoogleCodeExporter commented 9 years ago
Thanks for you reply.

I am using your picasa sample app. I tried to modify it to download all google
documents for a user. The login part works fine, but I get a 404 (NOT FOUND) 
error
when I send the following GET request on Android Emulator:
https://docs.google.com/feeds/documents/private/full
and header:
[User-Agent: google-documentlistsample-1.0 Google-API-Java/2.2.0-alpha(gzip),
Authorization: OAuth oauth_consumer_key="anonymous", 
oauth_nonce="698f4dd6eb7b3805",
oauth_signature="szA0gUI8i%2BAnXzU8ce4vyKBW%2BYw%3D",
oauth_signature_method="HMAC-SHA1", oauth_timestamp="1274615331",
oauth_token="1/thbXYaBfOHPSiUyisUYdrFQalckYEsiO4Pa9FbTqxNI", Accept-Encoding: 
gzip,
GData-Version: 3]

Do you have any ideas why this is happening?

Original comment by bgaborc...@gmail.com on 23 May 2010 at 11:55

GoogleCodeExporter commented 9 years ago
bgaborchen: the appropriate place to ask this question is in the Documents List 
API Help Forum:
http://www.google.com/support/forum/p/apps-apis/label?lid=5c316c702e844c99&hl=en

That said, my guess is that the URL is incorrect, and I think it should be 
https://docs.google.com/feeds/default/private/full

Original comment by yanivin...@gmail.com on 25 May 2010 at 1:52

GoogleCodeExporter commented 9 years ago
Hi, I am trying using version gdata-java-2.1.0-alpha but I have a doubt, I read 
in 
forum that I should use OAuth instead of account manager in my application, 
which also 
has the advantage of working across all Android devices, including the 1.5 SDK. 
But how to use OAuth and wat exact changes I have to make if I want to use 
OAuth in 
that Picasa sample example.

Original comment by mundhe.a...@gmail.com on 31 May 2010 at 11:01

GoogleCodeExporter commented 9 years ago
Closing this issue since Android is not supported by the version 1 client 
library.  Please direct further questions to the Google Group 
(http://groups.google.com/group/gdata-java-client).

Regarding OAuth vs. AccountManager.  AccountManager is the preferred choice 
because it provides a much better user experience.  OAuth is only recommended 
if you need support for older Android devices like 1.5 and 1.6.  Please take a 
look at the Picasa Web Albums example for a detailed example of both approaches 
(http://gdata-java-client.googlecode.com/svn/tags/2.2.1-alpha/sample/picasa/pica
sa-atom-android-sample/instructions.html).

Original comment by yanivin...@gmail.com on 16 Jun 2010 at 4:18

GoogleCodeExporter commented 9 years ago
I've also refactored your Picasa sample to integrate into Google Docs.  I'm 
continually getting an expired token when I run the sample - though the 
original code works perfectly against Picasa. Any idea why Docs would act 
differently than Picasa?

Original comment by NickLong...@gmail.com on 19 Jun 2010 at 3:13

GoogleCodeExporter commented 9 years ago
NickLonginow: great question (I don't actually know the answer), but please ask 
it on the Google Group (gdata-java-client).

Original comment by yanivin...@gmail.com on 22 Jun 2010 at 7:16

GoogleCodeExporter commented 9 years ago
Solved.  Your code works perfectly as-is.  If it helps, I'd be willing to post 
my example google-docs version of your Picasa into the SVN as a help to others.

Question - your example here opens a Browser via the webintent (to capture user 
acceptance of access to google site by the app).  Any idea how to kill that 
window (browser) once done?  Might confuse the user later if they see it still 
sitting there, ie, if they do a back-button click...

Original comment by NickLong...@gmail.com on 24 Jun 2010 at 2:25