Due to PHP limitation php://input stream is not available when Content-type is multipart/form-data.

See: http://ua.php.net/manual/en/wrappers.php.php:
php://input is not available with enctype="multipart/form-data".

Services REST server try to read RAW data from input stream and fails, because it is empty. So, we are unable to have any resource that can upload file AND some other data in the same time.

Comments

taran2l’s picture

Here's a patch against 7.x-3.x latest version. Please review.

kylebrowning’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, REST-server-multipart-handling-1324818-1.patch, failed testing.

kylebrowning’s picture

I think the bot is fucked up?

kylebrowning’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, REST-server-multipart-handling-1324818-1.patch, failed testing.

taran2l’s picture

Version: 7.x-3.0 » 7.x-3.x-dev
taran2l’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, REST-server-multipart-handling-1324818-1.patch, failed testing.

marcingy’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, REST-server-multipart-handling-1324818-1.patch, failed testing.

taran2l’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, REST-server-multipart-handling-1324818-1.patch, failed testing.

ygerasimov’s picture

I ran tests locally and it looks there is no fails. Bot doesn't work properly.

Meanwhile regarding the patch, it introduces trailing spaces and some styling corrections should be done.

+        // see http://php.net/manual/en/wrappers.php.php
+        if($mime == 'multipart/form-data') {
+          $data = call_user_func($parser);

should have space after "if"

+++ b/servers/rest_server/includes/RESTServer.incundefined
@@ -271,18 +271,23 @@ class RESTServer {
+          $data = call_user_func($parser);
+        } else {
+          // Read the raw input stream

should be

{
else {
+++ b/servers/rest_server/includes/RESTServer.incundefined
@@ -470,6 +475,11 @@ class RESTServer {
+  ¶
+  public static function parseMultipart() {
+    return $_POST;
+  }

trailing spaces introduced

What is the use case when we receive enctype="multipart/form-data" and have both uploaded file and POST data? I would love to have a test for this case. I have only form submit on my mind.

@Taran2l Could you please reroll the patch with style corrections and let me know what do you think about use case?

Thanks!

taran2l’s picture

@ygerasimov

Here's my use case: We have an Android application, which depends on Web portal. We need to store a file and device ID from the application.

So, we have created a new resource with argument device ID (Services does not allow to have a FILE type argument. Probably this moment should be improved too). Callback function copies a file resource example to save file, that have been transferred.

Do you know how to achieve this functionality with current Services implementation (maybe I'm missing something in the Services module architecture) ?

Thanks!

P.S. Rerolled patch attached.

taran2l’s picture

Sorry, wrong patch in #15. Attached proper version.

kylebrowning’s picture

Status: Needs work » Reviewed & tested by the community

This patch looks good to me.

Taran, you can do all sorts of alters on the resources or even pre-processing every call. But if you need to explicitly handle files a different way, you can always alter the resource definition via hook_services_resources_alter

We need a 6.x of this when its committed.

marcingy’s picture

Status: Reviewed & tested by the community » Fixed

Committed thanks

kylebrowning’s picture

Status: Fixed » Patch (to be ported)
kylebrowning’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
kylebrowning’s picture

Status: Patch (to be ported) » Closed (fixed)
arski’s picture

Status: Closed (fixed) » Patch (to be ported)

Sorry but it seems that you forgot to commit the following somehow (in the 6.x branch at least):

public static function parseMultipart() {
  return $_POST;
}

Everything else from the patch is nicely in the latest stable release and the -dev.. but this sadly ain't.. which breaks everything obviously :)

Cheers

kylebrowning’s picture

Status: Patch (to be ported) » Closed (fixed)

Fixed. Thanks

kylebrowning’s picture

Issue summary: View changes

fixed typo.