首页 文章

代号一个数据上传适用于Android手机,但在Iphone 4上失败

提问于
浏览
3

我正在尝试使用Codename One构建一个应用程序,该应用程序将从相机捕获的照片上传到服务器,然后将其与GPS坐标一起缩小到300x300 .

在模拟器(Iphone或ANdroid)上一切正常,照片被接收并存储在服务器上,其他数据也是如此 . 构建Android应用程序后,它在Android上也能正常运行 .

然而,当涉及到构建iOS应用程序并在我的Iphone 4上测试时,从未收到照片 . 实际上,数据没有通过Laravel中的验证器:

$validator = Validator::make($submittedData->all(), [ 'longitude' => 'required|numeric', 'latitude' => 'required|numeric', 'accuracy' => 'required|numeric', 'pic' => 'required|image|mimes:jpeg|max:100', ]);

通常接收文件的大小约为10k,但是从laravel的日志中报告的小于1k:

[2016-05-18 15:27:10] local.INFO: POST /public/www/API/storeAPI HTTP/1.1
Accept:          */*
Accept-Encoding: gzip, deflate
Accept-Language: fr-fr
Connection:      close
Content-Length:  518
Content-Type:    multipart/form-data; boundary=154c47a4886
Cookie:          cluster=R2881455720
Host:            lambda.fr
Remote-Ip:       x.y.z.a
User-Agent:      MyApp/2.8 CFNetwork/672.1.15 Darwin/14.0.0
X-Predictor:     1

所以我不确定我是否在Codename One中做错了什么,或者它是否与Laravel有关 .

在CN1中,我使用以下方法发送数据:

`MultipartRequest requete = new MultipartRequest();

                requete.setUrl(URL_DEST);
                requete.setTimeout(ParametresGeneraux.REQUEST_TIMEOUT);
                requete.setPost(true);
                requete.setFailSilently(true);
                requete.setSilentRetryCount(ParametresGeneraux.SEND_NUMBER_OF_RETRY);


                    requete.addData("pic", storageDir + imgPath, "image/jpeg");
                    requete.addArgument("latitude", Double.toString(location.getLatitude()));
                    requete.addArgument("longitude", Double.toString(location.getLongitude()));
                    requete.addArgument("accuracy", Double.toString(location.getAccuracy()));

                    NetworkManager.getInstance().addToQueueAndWait(requete);`

任何帮助将不胜感激,使图片上传也适用于iPhone设备!

编辑1:我发送的已调整大小的图像(上面的“storageDir imgPath”)在我的Iphone上的长度为0B(虽然它可以在Android和模拟器上运行) . 所以我将仔细研究一下从StateMachine启动的resizing方法,如下所示 .

编辑2:如果我添加给出文件长度的行,我在模拟器中得到一个值,但在真正的Iphone 4设备上得到0 . 因此,我的初始问题与上传文件但与路径无关 . 我应该开一个新问题吗?

`public static final boolean resizeImageFile (Image image, String outpath, String outFormat, final int width, final int height) {
    Image scaledImage = image.scaled(width, height);

    // Par défaut on prend le format jpeg
    if(!(outFormat.equals(ImageIO.FORMAT_JPEG) || outFormat.equals(ImageIO.FORMAT_PNG)) ){
        outFormat = ImageIO.FORMAT_JPEG;
    }

    try {
        OutputStream os = Storage.getInstance().createOutputStream(outpath);
        if ( scaledImage != null ) {                /*
         * ATTENTION le paramètre de qualité ne semble pas être pris en compte
         */
            ImageIO.getImageIO().save(scaledImage, os, outFormat, ParametresGeneraux.getPicQuality());
            os.close();

/ * ADDED LINE FOR EDIT 2 * / Dialog.show(“保存文件的大小”,FileSystemStorage.getInstance() . getLength(HOME_DIR filename)“B”,“OK”,null); //这在模拟器上显示xxxB,在设备上显示0B(Iphone 4)

return true;
        }
        else {
            return false;
        }

    } catch (IOException e) {

        return false;
    }
}`

编辑3:最后,问题已通过以下方式解决 . 而不是使用Storage.getInstance() . createOutputStream(outpath);它将文件(这里是outputpath)存储在Storage的某个地方,我切换到OutputStream os = FileSystemStorage.getInstance() . openOutputStream(outpath);由于FileSystemStorage仅处理绝对路径,如果outpath = FileSystemStorage.getInstance() . getAppHomePath aFileNameOfYourChoice,则可以使用requete.addData(“pic”,FileSystemStorage.getInstance() . getAppHomePath aFileNameOfYourChoice,“image / jpeg”)发送数据;

问候

1 回答

  • 1

    您需要始终使用 FileSystemStorage 并始终使用文件的绝对路径来上载它 . Storage 更简单,并从本机OS 's thus it means different things on different OS'中抽象出来 .

相关问题