0

つい最近、multipart/form-data アップロードのサポートが Restler v3 ( source ) に追加されましたが、動作しません。私の index.php ファイルに、次を追加しました。

$r->setSupportedFormats('JsonFormat', 'UploadFormat');

.txt ファイルを投稿すると、次のエラーが表示されます (既定の「許可された」形式は「image/jpeg」、「image/png」であるため、これは予期されたものです。

"error": {
    "code": 403,
    "message": "Forbidden: File type (text/plain) is not supported."
}

しかし、.jpg ファイルを投稿すると、代わりに次のエラーが表示されます。

"error": {
    "code": 404,
    "message": "Not Found"
}

私は何が欠けていますか?これが私の機能です:

function upload() {
    if (empty($request_data)) {
        throw new RestException(412, "requestData is null");
    }
    return array('upload_status'=>'image uploaded successfully');
}
4

1 に答える 1

1

私はそれを考え出した!関数が必要なだけpost()です!私が遭遇した同じ問題に遭遇した人のために、Restler 3 でファイルをアップロードするための私の解決策を次に示します。

index.php

<?php
    require_once '../vendor/restler.php';
    use Luracast\Restler\Restler;

    $r = new Restler();    
    $r->addAPIClass('Upload');  
    $r->setSupportedFormats('JsonFormat', 'UploadFormat');

    $r->handle();

Upload.php

<?php
    class Upload {
        function get(){
           if (empty($request_data)) {
              throw new RestException(412, "requestData is null");
           }
        }

        function post($request_data=NULL) {
           return array('upload_status'=>'image uploaded successfully!');
        }
    }
于 2013-03-31T21:34:16.333 に答える