Php 将图像从Android上载到服务器-仅上载图像的一部分

Php 将图像从Android上载到服务器-仅上载图像的一部分,php,android,image,Php,Android,Image,我的应用程序需要将多个图像上载到服务器。我通过解码Base64发送图像 Bitmap bitmapOrg = BitmapFactory.decodeFile(imagePath); ByteArrayOutputStream bao = new ByteArrayOutputStream(); bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao); byte [] ba =

我的应用程序需要将多个图像上载到服务器。我通过解码Base64发送图像

        Bitmap bitmapOrg = BitmapFactory.decodeFile(imagePath);
        ByteArrayOutputStream bao = new ByteArrayOutputStream();
        bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);
        byte [] ba = bao.toByteArray();
        ba1 = Base64.encodeBytes(ba);
而在


现在我可以看到,一些图片只是部分上传。我只能看到图像最上面的几位,而服务器上的所有内容都是空白的。可能有什么问题?使用Base64解码有什么缺点吗?

请使用这种方法。我希望它对您有用。在您的代码中,可能是图像像素显示得太高了。然后您无法在服务器中看到图像

/**
     * encodes image to string using Base64
     * 
     * @return String imageString
     */
    **

private String prepareImage() {
        if (tempPath == null || (!isProfilechanged)) {
            return "";
        }
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap bitmap = BitmapFactory.decodeFile(tempPath, options);
        bitmap = Bitmap.createScaledBitmap(bitmap, 50, 50, true);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // bitmap.compress(Bitmap.CompressFormat.PNG, 50, baos);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
        byte[] byteArray = baos.toByteArray();
        String imageString = com.qwiches.utils.Base64.encodeBytes(byteArray);
        bitmap = null;
        System.gc();
        Runtime.getRuntime().gc();
        return imageString;
    }
**

尝试下载该文件,以确保文件已完全上载


您可以检查此选项以在android中生成文件的校验和

注意,如果您需要高质量的图像,此方法将不适用于您,因为它会将图像缩放到50x50px。是。因为当图像大小太大时,则无法在不缩放的情况下上载服务器。如果OP不关心分辨率,那么你的解决方案就行了。如果他真的在乎,你的就行不通了。“这是我唯一的观点。”迪帕利,这对压缩你的方式和我的方式有什么不同?我是说,这是不是因为没有上传整个文件的问题?还是只是为了减小尺寸??你能建议检查一下图像是否完全上传到服务器上吗?@NathanWalters,我不需要很好的像素。因此,如果它解决了问题,这个解决方案是好的。但如果只是为了缩小尺寸,我认为这不是解决办法。你能建议检查一下图像是否完全上传到服务器上吗?
/**
     * encodes image to string using Base64
     * 
     * @return String imageString
     */
    **

private String prepareImage() {
        if (tempPath == null || (!isProfilechanged)) {
            return "";
        }
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap bitmap = BitmapFactory.decodeFile(tempPath, options);
        bitmap = Bitmap.createScaledBitmap(bitmap, 50, 50, true);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // bitmap.compress(Bitmap.CompressFormat.PNG, 50, baos);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
        byte[] byteArray = baos.toByteArray();
        String imageString = com.qwiches.utils.Base64.encodeBytes(byteArray);
        bitmap = null;
        System.gc();
        Runtime.getRuntime().gc();
        return imageString;
    }