I also tried Shais code from stack oveflow,

Button upload = new Button("Upload");
hi.add(upload);
upload.addActionListener(e -> {
    String file = Capture.capturePhoto();
    if(file != null) {
        try {
            String uniqueFileName = "Image" + System.currentTimeMillis() + 
".jpg";
            MultipartRequest rq = new MultipartRequest();
            rq.setUrl("https://s3.amazonaws.com/my-bucket/";);
            rq.addArgument("key", uniqueFileName);
            rq.addArgument("acl", "private");
            rq.addData("file", file, "image/jpeg");
            rq.setReadResponseForErrors(true);
            NetworkManager.getInstance().addToQueueAndWait(rq);            
            if(rq.getResponseCode() != 200 && rq.getResponseCode() != 204) {
                System.out.println("Error response: " + new 
String(rq.getResponseData()));
            }
            ToastBar.showMessage("Upload completed", FontImage.MATERIAL_INFO);
        } catch(IOException err) {
            Log.e(err);
        }
    }});




this gives me the error 

java.io.IOException: Error writing to server
at 
sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:666)
at 
sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:678)
at 
sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1534)
at 
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at 
sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at 
com.codename1.impl.javase.JavaSEPort.getResponseCode(JavaSEPort.java:6248)
at 
com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:403)
at 
com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:282)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
java.lang.NullPointerException
at java.lang.String.<init>(String.java:566)
at userclasses.StateMachine.initVars(StateMachine.java:56)
at generated.StateMachineBase.startApp(StateMachineBase.java:54)
at generated.StateMachineBase.<init>(StateMachineBase.java:31)
at generated.StateMachineBase.<init>(StateMachineBase.java:96)
at userclasses.StateMachine.<init>(StateMachine.java:26)
at com.norby.uploader.NorbyS3.start(NorbyS3.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.codename1.impl.javase.Executor$1$1.run(Executor.java:106)
at com.codename1.ui.Display.processSerialCalls(Display.java:1151)
at com.codename1.ui.Display.mainEDTLoop(Display.java:968)
at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
Java Result: 1

On Wednesday, July 5, 2017 at 6:53:24 PM UTC+8, Gareth Murfin wrote:
>
> I found some code that is supposed to work from stack over flow for s3 
> upload (shown below). However I always get this error when I try it
>
> java.io.IOException: Error writing to server
> at 
> sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:666)
> at 
> sun.net.www.protocol.http.HttpURLConnection.writeRequests(HttpURLConnection.java:678)
> at 
> sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1534)
> at 
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
> at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
> at 
> sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
> at 
> com.codename1.impl.javase.JavaSEPort.getResponseCode(JavaSEPort.java:6248)
> at 
> com.codename1.io.ConnectionRequest.performOperation(ConnectionRequest.java:403)
> at 
> com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:282)
> at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
>
>
> private void doUpload()
>     {
>         try {
>             String strImage = Capture.capturePhoto();
>             String s3Bucket = "https://usaeasygazy.s3.amazonaws.com";;  
>  //usa ones are easier no redirects?
>             String fileName = "ARSE";
>             MultipartRequest rq = new MultipartRequest();
>             rq.setUrl(s3Bucket);
>             rq.addArgumentNoEncoding("key", fileName);
>             //rq.addArgument("acl", "public-read-write"); // here I give 
> read-write access
>             rq.addArgument("acl", "bucket-owner-full-control");
>             rq.addData("file", strImage, "image/jpeg");
>             
>             _("add request to queue");
>             NetworkManager.getInstance().addToQueue(rq);
>             _("done");
>         } catch (IOException ex) {
>             _("ERROR DURING UPLOAD.! "+ex.getMessage());
>         }
>     }
>

-- 
You received this message because you are subscribed to the Google Groups 
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/codenameone-discussions/de6a9dda-564d-4313-9b5d-69cded9f247c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to