Comments

klausi’s picture

workaround: only PUT the promoted flag back and remove the image field.

emmonsaz’s picture

StatusFileSize
new2.69 KB

Here's a patch that supports the "Image" type that you may find useful.

emmonsaz’s picture

StatusFileSize
new2.73 KB

minor bug fix to my previous patch

emmonsaz’s picture

StatusFileSize
new3.03 KB

Here's a third update that corrects an issue when user id is not set.

btopro’s picture

Issue summary: View changes
Status: Active » Needs work

Built on this to work with the file_entity module which turns files into full blown entities (which restws can then utilize). Again, not a full blown solution but this combines patch 4 with new code that sees if the item it currently is receiving is a file resource and has a uri. If it does, it will perform the same kind of operation as the patch in #4 except specific to the file operation. It then correctly saves and returns the json output of the saved file. This only works with images and for my purposes I needed to save to private file directory uri schema.

/**
          * Add image field support (base64)
          * @author BLE
          * @version 1.2
          */
          // intercept payload and convert for manipulation
          $payload_array = json_decode($payload);
          // check for file entity uri property
          if ($resource_name == 'file' && isset($payload_array->uri)) {
            // get base64 image string
            $base64_data = (isset($payload_array->uri)) ? $payload_array->uri : null;
            // remove base64 prefix metadata, if exists
            $result = preg_split('/^data\:image\/(.*)\;base64\,/', $base64_data, -1, PREG_SPLIT_NO_EMPTY);
            if (count($result) > 0) {
              // replace any spaces with base64-compliant '+' signs and convert to binary image
              $data = base64_decode(str_replace(' ', '+', $result[0]));
              // base64 string may not have included a metadata prefix so create instance to determine mime type
              $finfo = finfo_open();
              $mime_type = finfo_buffer($finfo, $data, FILEINFO_MIME_TYPE);
              finfo_close($finfo);
              // get and validate image extension from mime type
              $ext = str_replace('image/', '', $mime_type);
              if ($ext == "png" || $ext == "gif" || $ext == "jpeg") {
                // create filename (format: entity_name_timestamp.ext, e.g. favorite_color_survey_1363723712.png)
                $filename = $payload_array->{"type"} . "_" . time() . "." . $ext;
                // save binary image in Drupal site's private file directory
                if ($file = file_save_data($data, "private://" . $filename)) {
                  // replace the base64 image string in the payload with the file id reference of the newly created image
                  file_save($file);
                  // convert the payload back to a json string
                  $payload = json_encode($file);
                  print $payload;
                  drupal_add_http_header('Status', '201 Created');
                }
              }
            }
          }
          else {
            // get field information for specified entity and type (bundle)
            $fields_info = field_info_instances($resource_name, $payload_array->type);
            // loop through each field looking for image type
            foreach ($fields_info as $field_name => $value) {
              $field_info = field_info_field($field_name);
              $type = $field_info['type'];
              if ($type == "image") {
                // get base64 image string
                $base64_data = (isset($payload_array->$field_name)) ? $payload_array->$field_name : null;
                // remove base64 prefix metadata, if exists
                $result = preg_split('/^data\:image\/(.*)\;base64\,/', $base64_data, -1, PREG_SPLIT_NO_EMPTY);
                if (count($result) > 0) {
                  // replace any spaces with base64-compliant '+' signs and convert to binary image
                  $data = base64_decode(str_replace(' ', '+', $result[0]));
                  // base64 string may not have included a metadata prefix so create instance to determine mime type
                  $finfo = finfo_open();
                  $mime_type = finfo_buffer($finfo, $data, FILEINFO_MIME_TYPE);
                  finfo_close($finfo);
                  // get and validate image extension from mime type
                  $ext = str_replace('image/', '', $mime_type);
                  if ($ext == "png" || $ext == "gif" || $ext == "jpeg") {
                    // create filename (format: entity_name_timestamp.ext, e.g. favorite_color_survey_1363723712.png)
                    $filename = $payload_array->{"type"} . "_" . time() . "." . $ext;
                    // save binary image in Drupal site's private file directory
                    if ($file = file_save_data($data, "private://" . $filename)) {
                      file_save($file);
                      // replace the base64 image string in the payload with the file id reference of the newly created image
                      $payload_array->$field_name = array('fid' => $file->fid);
                    }
                  }
                }
              }
            }
            // convert the payload back to a json string
            $payload = json_encode($payload_array);
nicxvan’s picture

I'm struggling with getting this working.

When I attempt to use this patch I get the following error:

Parse error: syntax error, unexpected 'elseif' (T_ELSEIF) in sites/all/modules/restws/restws.module on line 217

which leads me to believe that I'm missing a brace below $payload.

I then get an error:Warning: preg_split() expects parameter 2 to be string, object given in restws_handle_request() (line 188 of

The array I'm passing is:
'field_images' => array(
'type' => 'jpeg',
'file' => 'base 64 code'
)

nicxvan’s picture

I've also tried:

'field_images' => "base 64 code'

And I get a 406 error
406 Not Acceptable: Invalid data value given. Be sure it matches the required data type and format.

btopro’s picture

Here's an example I've been using on something I'm working on
curl -u USER:PASSWORD https://ADDRESS.COM/node/ -X POST -H"Content-Type: application/json" -d '{"type":"photonode","field_images":"data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAKQWlDQ1BJQ0MgUHJvZmlsZQAASA2dlndUU9kWh8+9N73QEiIgJfQaegkg0jtIFQRRiUmAUAKGhCZ2RAVGFBEpVmRUwAFHhyJjRRQLg4Ji1wnyEFDGwVFEReXdjGsJ7601896a/cdZ39nnt9fZZ+9917oAUPyCBMJ0WAGANKFYFO7rwVwSE8vE9wIYEAEOWAHA4WZmBEf4RALU/L09mZmoSMaz9u4ugGS72yy/UCZz1v9/kSI3QyQGAApF1TY8fiYX5QKUU7PFGTL/BMr0lSkyhjEyFqEJoqwi48SvbPan5iu7yZiXJuShGlnOGbw0noy7UN6aJeGjjAShXJgl4GejfAdlvVRJmgDl9yjT0/icTAAwFJlfzOcmoWyJMkUUGe6J8gIACJTEObxyDov5OWieAHimZ+SKBIlJYqYR15hp5ejIZvrxs1P5YjErlMNN4Yh4TM/0tAyOMBeAr2+WRQElWW2ZaJHtrRzt7VnW5mj5v9nfHn5T/T3IevtV8Sbsz55BjJ5Z32zsrC+9FgD2JFqbHbO+lVUAtG0GQOXhrE/vIADyBQC03pzzHoZsXpLE4gwnC4vs7GxzAZ9rLivoN/ufgm/Kv4Y595nL7vtWO6YXP4EjSRUzZUXlpqemS0TMzAwOl89k/fcQ/+PAOWnNycMsnJ/AF/GF6FVR6JQJhIlou4U8gViQLmQKhH/V4X8YNicHGX6daxRodV8AfYU5ULhJB8hvPQBDIwMkbj96An3rWxAxCsi+vGitka9zjzJ6/uf6Hwtcim7hTEEiU+b2DI9kciWiLBmj34RswQISkAd0oAo0gS4wAixgDRyAM3AD3iAAhIBIEAOWAy5IAmlABLJBPtgACkEx2AF2g2pwANSBetAEToI2cAZcBFfADXALDIBHQAqGwUswAd6BaQiC8BAVokGqkBakD5lC1hAbWgh5Q0FQOBQD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zI8L3RpZmY6WFJlc29sdXRpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgrAtDS6AAAAGklEQVQIHWNUkpP/z8TMzMDEyMjI8P/fPwYAHYEEaDdGOeUAAAAASUVORK5CYII="}'

The data:image/jpeg;base64, part at the beginning is critical cause if you step through the code its looking to do a preg split based on the data and base64 items being there

nicxvan’s picture

Thanks I'll test that!
Off the top of your head what would it take to get this working with pdfs as well?

btopro’s picture

honestly probably not that much; there are direct references to "image" and "images" as well as saving to the private file system and the extensions to accept / tack on (png/gif/jpeg). This leads me to believe that while I'm not positive it's probably not that hard (anything can be a base 64 encoded file to my knowledge).

This is not at all a "generic" patch (hence hasn't been accepted) it's a very specific use-case of getting a specific type of file accepted. You could probably hack it to do other files pretty easy.

A more sustainable solution that should consider being accepted would accept any kind of base64 data if noticed (and if the file field accepted it and if the role had permission to do so and blah blah blah) and then look at the way that file field has been configured and store things correctly (and reject them if they aren't the right file extension type / too big).

nicxvan’s picture

Ok I got this working a couple tips for posterity.

I found I did not need file entity or private system path so I used emmonsaz's patch.

I used btopro's image, it needed me to pass a string not an array like the image field looks like it needs by default. You have to pass the whole things as a string.

tdiprima33’s picture

Status: Needs work » Needs review
StatusFileSize
new3.38 KB

Based on several posts I've read that have to do with the ability to upload images, please review this patch.

Thank you.

Status: Needs review » Needs work

The last submitted patch, 12: restws.module-1819594.patch, failed testing.

tdiprima33’s picture

Status: Needs work » Active

@nicxvan, do you mean that you used @emmonsaz's code patch, and used @btopro's example curl command for testing?

nicxvan’s picture

@tdiprima33 Sort of, I used @emmonaz's patch I pasted the part of btopro's code I used at the bottom. Just a note, I still can't get updates to work, only creates are working atm. Further, I can't get multi-value fields to work.

If it would help I can do a session with you and show you my code.

"field_images":"data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAYAAABytg0kAAAKQWlDQ1BJQ0MgUHJvZmlsZQAASA2dlndUU9kWh8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van’s picture

StatusFileSize
new7.06 KB

Turns out that this was only for creates, I have moved it to it's own function and made it work for both create and updates. Please review this patch

btopro’s picture

Glancing at the patch, assumption seems to be that if we aren't creating or querying that we should be assuming update. Would it make sense to have a case in there for $op == 'update' ?

nicxvan’s picture

@btopro I think that may be the case, because at the moment there doesn't seem to be a catch for DELETE. (I was planning on adding a boolean that triggered a rule to delete)

tdiprima33’s picture

Hi @nicxvan, thanks for the patch. I tried to git-apply it, but it won't apply.
IDK if it's because in function restws_session_token() there is supposed to be a line:
drupal_add_http_header('Content-Type', 'text/plain');
But it's missing in your patch? Just an FYI.

tdiprima33’s picture

I am working under the assumption that we are POSTing to a Drupal node containing an image, correct?

If you do a GET on a node containing a field image, you get:
"field_image": { "file": { "uri": "http://somewhere/file/56", "id": "56", "resource": "file" } },

So where do you put the base64 string? There's no attribute for it. How is it that the example above works?
"field_images":"data:image/jpeg;base64,iVBORw0KGgoAAAANSU..."

nicxvan’s picture

@tdiprima33, you make the header in the php you are generating. As the title says though this is a PUT not a POST. PUT is for updating POST is for creating. I can hop on IRC tomorrow and explain it to you a bit better.

nicxvan’s picture

Status: Active » Needs review

@tdiprima33 How did you get your patch to be tested? Did you just change the status to needs review?

The last submitted patch, 2: restws.module.patch, failed testing.

The last submitted patch, 3: restws.module.patch, failed testing.

The last submitted patch, 4: restws.module.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 16: restws-imagesupport-1819594-16.patch, failed testing.

nicxvan’s picture

Status: Needs work » Needs review
StatusFileSize
new4.15 KB

Reroll

Status: Needs review » Needs work

The last submitted patch, 27: restws-imagesupport-1819594-23.patch, failed testing.

lokapujya’s picture

Issue tags: +Needs tests

If this had a test, it would be easier to debug.

nicxvan’s picture

StatusFileSize
new7.06 KB

Updated to handle multiple images of the format:

'field_image' => array(
      'data:image/jpeg;base64,'.encode_file('../sites/default/files/pengoothumb.jpg'),
      'data:image/jpeg;base64,'.encode_file('../sites/default/files/tulipthumb.jpg')
      )

encode_file is a basic function that just returns the base64 encoded image.

nicxvan’s picture

Status: Needs work » Needs review

Needs Testing

nicxvan’s picture

StatusFileSize
new7.2 KB

New patch on latest dev

The last submitted patch, 30: restws-imagesupport-1819594-29.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 32: restws-imagesupport-1819594-32.patch, failed testing.

nicxvan’s picture

I think this is failing because it checks entities that do not have images. However, adding a check to be sure the entity has images fixes the issue, but then images do not add to nodes correctly.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 32: restws-imagesupport-1819594-32.patch, failed testing.

btopro’s picture

StatusFileSize
new3.53 KB

reroll attempt after recent security update

lokapujya’s picture

Status: Needs work » Needs review

Test it.

Status: Needs review » Needs work

The last submitted patch, 38: restws-imagesupport-1819594-38.patch, failed testing.

mariano.barcia’s picture

I've built a module to deal with file/images in restws.

Please see #2452759: [D7] RESTful web services support for files and images.

Reviewing and testing welcome, thank you in advance.

mariano.barcia’s picture

Status: Needs work » Closed (won't fix)

Closing this issue as well, as per
https://www.drupal.org/project/restws_file
Please refer to it, thank you.