Codename One 数据上传在 Android phone 上有效,但在 Iphone 上失败 4

Codename One data upload works on Android phone but fails on Iphone 4

我正在尝试构建一个代号为 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

所以我不确定是我在代号一中做错了什么还是与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 和模拟器)。因此,我将让 closer 查看从 StateMachine 启动的调整大小方法,如下所示。

编辑 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();

/*为编辑 2 添加行 */ Dialog.show("Size of saved file", FileSystemStorage.getInstance().getLength(HOME_DIR + 文件名) + "B", "OK", 空); // 这在模拟器上显示 xxxB,在设备上显示 0B (Iphone 4)

            return true;
        }
        else {
            return false;
        }

    } catch (IOException e) {

        return false;
    }
}`

编辑 3:最后问题已通过以下方式解决。而不是使用 Storage.getInstance().createOutputStream(outpath);将文件(此处为输出路径)存储在存储中的某个位置,我切换到 OutputStream os = FileSystemStorage.getInstance().openOutputStream(outpath);由于 FileSystemStorage 只处理绝对路径,如果 outpath = FileSystemStorage.getInstance().getAppHomePath + aFileNameOfYourChoice 那么你可以发送数据 requete.addData("pic", FileSystemStorage.getInstance().getAppHomePath + aFileNameOfYourChoice, "image/jpeg");

此致

您需要始终使用 FileSystemStorage 并始终使用文件的绝对路径才能上传文件。 Storage 比原生 OS 更简单和抽象,因此它在不同的 OS 上意味着不同的东西。