Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Micropub: Upload of multiple photos fails #1508

Open
cweiske opened this Issue Sep 8, 2016 · 8 comments

Comments

Projects
None yet
3 participants
@cweiske
Copy link
Contributor

cweiske commented Sep 8, 2016

While trying to do this:

Create a note with two images via the micropub endpoint

$ curl -i -H 'Authorization: Bearer abc' -F 'h=entry' -F 'content=2 photos'\
     -F 'photo[]=@/path/to/image.png' -F 'photo[]=@/path/to/image2.png'\
     http://example.org/micropub

Passing two image URLs fails the same:

$ curl -H 'Content-Type: application/x-www-form-urlencoded' -H 'Authorization: Bearer abc'\
     -d 'h=entry' -d 'content=2 image urls'\
     -d 'photo[0]=http://example.org/1.jpg'\
     -d 'photo[1]=http://example.org/2.jpg' http://example.org/micropub

I encountered this error:

  • HTTP status code 200
  • no location header
  • no post created

Some other notes:

The micropub draft spec section 3.3 create says:

To specify multiple values for a property, such as multiple categories of an h-entry, use array bracket notation for the property name.

the error log says:

PHP Warning: getimagesize() expects parameter 1 to be string, array given in /home/cweiske/Dev/tools/known/Idno/Entities/File.php on line 196

@cweiske

This comment has been minimized.

Copy link
Contributor Author

cweiske commented Sep 22, 2016

Currently the photo upload functionality only supports a single photo in IdnoPlugins/Photo/Photo.php#saveDataFromInput(). Seems #215 must be solved first.

@mapkyca

This comment has been minimized.

Copy link
Member

mapkyca commented Jun 15, 2018

Is this working on more recent builds? I seem to remember fixing this...

@funwhilelost

This comment has been minimized.

Copy link

funwhilelost commented Nov 6, 2018

@mapkyca - no I've just confirmed this is still not working in 0.9.9

@funwhilelost

This comment has been minimized.

Copy link

funwhilelost commented Nov 6, 2018

I see your patch to the Photo class with support for multiple images but when they come in from a Micropub it looks like the call to Photo.php#saveDataFromInput() is still naive to the POST of multiple files:

if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name']) || \Idno\Entities\File::isSVG($_FILES['photo']['tmp_name'], $_FILES['photo']['name'])) {

Which then hits "isImage" with an array, throwing: PHP Warning: getimagesize() expects parameter 1 to be string, array given in /home/cweiske/Dev/tools/known/Idno/Entities/File.php on line 196

The $_FILES['photo'] variable looks like this when a multi-photo Micropub comes in:

array (
  'photo' =>
  array (
    'name' =>
    array (
      0 => 'igwg5NAI.jpg',
      1 => 'igddaDEG.jpg',
    ),
    'type' =>
    array (
      0 => 'image/jpeg',
      1 => 'image/jpeg',
    ),
    'tmp_name' =>
    array (
      0 => '/tmp/phpuup649',
      1 => '/tmp/phpWpSDJh',
    ),
    'error' =>
    array (
      0 => 0,
      1 => 0,
    ),
    'size' =>
    array (
      0 => 1540758,
      1 => 1496460,
    ),
  ),
)
@funwhilelost

This comment has been minimized.

Copy link

funwhilelost commented Nov 6, 2018

On looking through master I see that some work has been done to handle multiple photos by iterating over them. For me this just results in a Photo post with a single photo, but at least it doesn't error out!

@funwhilelost

This comment has been minimized.

Copy link

funwhilelost commented Nov 6, 2018

Confirmed after updating to master that this works well from OwnYourGram, posting a multi-photo post through Micropub. There is a kind of odd anomaly, though:

image

@mapkyca

This comment has been minimized.

Copy link
Member

mapkyca commented Nov 6, 2018

The question mark is placed there whenever the browser fails to load the image, for whatever reason. Sometimes this is a one time network thing, but it could also be the format of the image.

Logs might be able to tell you, or you could edit the post and attempt to upload that file again.

@funwhilelost

This comment has been minimized.

Copy link

funwhilelost commented Nov 8, 2018

@mapkyca in this case it's throwing in an odd "user" block at the end of the content:

<div class="e-content entry-content multiple-images" data-num-pics="2">
                <div class="photo-view">
                <a href="https://www.funwhilelost.com/file/9f8949188077202f00631a2cd888aa2f/igQXl4jv.jpg" data-gallery="Long grind up that forest service road but it's tough to beat the view at Sun Top Lookout. " data-original-img="https://www.funwhilelost.com/file/9f8949188077202f00631a2cd888aa2f/igQXl4jv.jpg" data-title="Long grind up that forest service road but it's tough to beat the view at Sun Top Lookout. " data-footer=""><img src="https://www.funwhilelost.com/file/c9037e0d90a5d4126b45c0e70a50bfdb/thumb.jpg" class="u-photo" alt="Long grind up that forest service road but it's tough to beat the view at Sun Top Lookout. "></a>
            </div>
                        <div class="photo-view">
                <a href="https://www.funwhilelost.com/file/82d99c16ef564e9196b2a5e9fbd7251a/igoy4bhK.jpg" data-gallery="Long grind up that forest service road but it's tough to beat the view at Sun Top Lookout. " data-original-img="https://www.funwhilelost.com/file/82d99c16ef564e9196b2a5e9fbd7251a/igoy4bhK.jpg" data-title="Long grind up that forest service road but it's tough to beat the view at Sun Top Lookout. " data-footer=""><img src="https://www.funwhilelost.com/file/36c9166a7c9fb47d1fe384d03a81c695/thumb.jpg" class="u-photo" alt="Long grind up that forest service road but it's tough to beat the view at Sun Top Lookout. "></a>
            </div>
                 <!-- WEIRD EMPTY PARAGRAPH -->
                <p></p>
                 
                <!-- WEIRD UNEXPECTED IMAGE -->
                <p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://www.funwhilelost.com/gfx/users/default.png" alt=""></p>        
                
                 <p class="tag-row">
                        <i class="fa fa-tag"></i>
                        <a href="https://www.funwhilelost.com/tag/+%23mountainbike" class="p-category" rel="tag"> #mountainbike</a>
                         ...
                  </p>      
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.