gyselroth / balloon

High performance, feature rich document management system written for the cloud
GNU General Public License v3.0
18 stars 7 forks source link

Balloon Image Upload via V1 api failed #416

Closed jakov-ratkovic closed 4 years ago

jakov-ratkovic commented 4 years ago

Describe the bug

Uploading an Image to Balloon throws an Exception.

{"error":"MongoDB\GridFS\Exception\FileNotFoundException","message":"File \"{ \"_id\" : { } }\" not found in \"balloon.fs.files\"","code":0}

To Reproduce

The Api call is /api/v1/file?p=PATH

Expected behavior

The Image should be uploaded without any Problems.

Environment

-balloon server version v2.7.0-beta1

raffis commented 4 years ago

@jakov-ratkovic I can not reproduce this, uploading a new file via the api v1 works:

curl -v -u admin:admin localhost:8084/api/v1/file?p=/nnnnnn/file.png -XPUT --data @/home/raffael/Pictures/Selection_003.jpg 
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8084 (#0)
* Server auth using Basic with user 'admin'
> PUT /api/v1/file?p=/nnnnnn/file.png HTTP/1.1
> Host: localhost:8084
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Length: 7573
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 201 Created
< Server: nginx/1.15.8
< Date: Fri, 06 Dec 2019 15:51:14 GMT
< Content-Type: application/json; charset=utf-8
< Content-Length: 48
< Connection: keep-alive
< X-Powered-By: PHP/7.3.12
< 
* Connection #0 to host localhost left intact
{"status":201,"data":"5dea78f235df7c29610c78d4"}

Can you please provide more details. What is your path? Does it work with another path? How does your request look like?

jakov-ratkovic commented 4 years ago

Tried a couple different paths out they all do not work. Path example: micropagebilder/micropagebilder_kzu/pageImages_90/newsImages_6.jpg

Variables and Constants in the API Request

CURLOPT_HEADER = 42
CURLOPT_INFILE = 10009
CURLOPT_INFILESIZE = 14
CURLOPT_PUT = 54
CURLOPT_RETURNTRANSFER = 19913
CURLOPT_URL = 10002

$uploadFile = resource id='19' type='stream'
$fileSize = 6976
$apiUrl = https://balloonstage.tam.ch/api/v1
$path = micropagebilder/micropagebilder_kzu/pageImages_90/newsImages_6.jpg

The API Request:

$curlHandle = self::_init($user, $password, $authType);

 \curl_setopt($curlHandle, CURLOPT_HEADER, false);
 \curl_setopt($curlHandle, CURLOPT_INFILE, $uploadFile);
 \curl_setopt($curlHandle, CURLOPT_INFILESIZE, $fileSize);
 \curl_setopt($curlHandle, CURLOPT_PUT, true);
 \curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
 \curl_setopt($curlHandle, CURLOPT_URL, $apiUrl . '/file?p=' . $path);

 $curlResult = \curl_exec($curlHandle);
 $curlInfo   = \curl_getinfo($curlHandle);
 \curl_close($curlHandle);

ouput :

$curlResult = {"error":"MongoDB\\GridFS\\Exception\\FileNotFoundException","message":"File \"{ \"_id\" : {  } }\" not found in \"balloon.fs.files\"","code":0}

$curlinfo = Array
(
    [url] => https://balloonstage.tam.ch/api/v1/file?p=micropagebilder/micropagebilder_kzu/pageImages_90/newsImages_6.jpg
    [content_type] => application/json; charset=utf-8
    [http_code] => 500
    [header_size] => 216
    [request_size] => 249
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.547516
    [namelookup_time] => 0.060413
    [connect_time] => 0.06232
    [pretransfer_time] => 0.113686
    [size_upload] => 6976
    [size_download] => 144
    [speed_download] => 263
    [speed_upload] => 12753
    [download_content_length] => 144
    [upload_content_length] => 6976
    [starttransfer_time] => 0.197802
    [redirect_time] => 0
    [redirect_url] => 
    [primary_ip] => 10.50.0.100
    [certinfo] => Array
        (
        )

    [primary_port] => 443
    [local_ip] => 172.17.0.2
    [local_port] => 45432
    [http_version] => 2
    [protocol] => 2
    [ssl_verifyresult] => 0
    [scheme] => HTTPS
)
raffis commented 4 years ago

Please try with another file, this seems like some issue in your local environment and not a bug in the api.

jakov-ratkovic commented 4 years ago

Tried it on different modules on intranet an with different files and i get the same error message.

I even tried it on Ballon directly without the API and i get the same Error. Screenshot from 2019-12-11 09-38-41

Update: The first Time an Image gets uploaded it works but after deleting it and retrying with same Image it gives an error

raffis commented 4 years ago

Bug in v2.7 beta:

balloon-dev_1       | 2019-12-11 09:16:10 [Micro\Http\Router,ERROR]: uncaught exception invalid id given] {"exception":"[object] (Balloon\\Filesystem\\Exception\\InvalidArgument(code: 0): invalid id given at /srv/www/balloon/src/lib/Filesystem.php:336)
balloon-dev_1       | [stacktrace]
balloon-dev_1       | #0 /srv/www/balloon/src/app/Balloon.App.Api/v2/Files.php(151): Balloon\\Filesystem->getNode(NULL, 'Balloon\\\\Filesys...')
balloon-dev_1       | #1 /srv/www/balloon/src/app/Balloon.App.Api/v2/Files.php(89): Balloon\\App\\Api\\v2\\Files->getParent(NULL, NULL)
balloon-dev_1       | #2 [internal function]: Balloon\\App\\Api\\v2\\Files->putChunk(NULL, NULL, NULL, 'newsImages_6.jp...', 1, 1, 6976, 0, NULL, NULL, NULL, NULL, NULL)
balloon-dev_1       | #3 /srv/www/balloon/vendor/gyselroth/micro-http/src/Router.php(246): call_user_func_array(Array, Array)
balloon-dev_1       | #4 /srv/www/balloon/src/lib/Bootstrap/Http.php(91): Micro\\Http\\Router->run()
balloon-dev_1       | #5 /srv/www/balloon/src/httpdocs/index.php(47): Balloon\\Bootstrap\\Http->process()
balloon-dev_1       | #6 {main}
balloon-dev_1       | "} []

Steps to reproduce:

  1. Upload file x as user a
  2. Upload the same file (identical hash) as user b results in 422 - InvalidArgument
raffis commented 4 years ago
2. Upload the same file (identical hash) as user b results in 422 - InvalidArgument

This is actually another bug in v2.7 beta1 and happens only within the root collection.

The initial bug reported here applies if a file with an identical checksum already existed in a pre v2.7 installation and occurs while uploading the same file again to a different location with v2.7.

raffis commented 4 years ago

fix will be part of v2.7.0-beta2, thanks for testing.