Search code examples
androidamazon-web-servicesfile-upload

How to upload .mobileconfig and txet file in amazon server in android


Hello friends i m trying to upload file or .mobileconfig in amazon server , but i m not able to upload file in amazon server , i can upload the image in amazon server . Please friend help me how to upload the file in amazon server in android.


Solution

  • finally got the answer

            // Put the image data into S3.
            try {
    
    
                String bucketw = getPictureBucket();
                Log.d("ddddd", "bucketw :  " + bucketw);
    
                // Content type is determined by file extension.
                // PutObjectRequest por = new PutObjectRequest(
                // getPictureBucket(), Constants.PICTURE_NAME,
                // new java.io.File(filePath));
                System.out.println(finammane);
    
                //
                String bucket = "vpnme";
                File file = new File("/mnt/sdcard/vp.txt");
                InputStream in = new FileInputStream("/mnt/sdcard/vp.txt");
    
                ByteArrayOutputStream out = new ByteArrayOutputStream();
    
                byte[] buffer = new byte[1024]; // you can configure the buffer
                                                // size
                while (in.read(buffer) != -1)
                    out.write(buffer); // copy streams
    
                byte[] result2 = out.toByteArray();
                Long contentLength = Long.valueOf(result2.length);
    
                ObjectMetadata metadata = new ObjectMetadata();
                metadata.setContentLength(contentLength);
    
                PutObjectRequest por = new PutObjectRequest(getPictureBucket(),
                        finammane, new java.io.File("/mnt/sdcard/vp.txt")).withCannedAcl(
                        CannedAccessControlList.PublicRead).withMetadata(
                        metadata);
                s3Client.putObject(por);
                // Just set your directory
                // PutObjectRequest request = new
                // PutObjectRequest("my-unique-name",
                // "vpnme/" + Constants.PICTURE_BUCKET, file).withCannedAcl(
                // CannedAccessControlList.PublicRead).withMetadata(metadata);
                // s3Client.putObject(request);
                in.close();
                // buffer.
    
            } catch (Exception exception) {
                System.out.println("eeee" + exception);
                Log.d("e", "ee " + exception.getMessage());
    
                result.setErrorMessage(exception.getMessage());
            }