[QUESTION] Uploaded image don't show in App
- Your Rocket.Chat app version: 1.7.4 (126)
- Your Rocket.Chat server version: 0.59.4
- Device (or Simulator) you're running with: IPhone 5s
When trying to upload a image (doesn't matter if from camera or from media library) the upload works fine. But the image doesn't show up in App.

In WebUI (withFirefox) on the desktop computer the picture shows up, but if trying to view the image, a error is shown.
If trying to upload picture with firefox on the desktop computer everything works fine, the image shows up in app and browser.
Rocket.Chat server runs behind a nginx reverse proxy. NGinx logs following error when i try to load the image from any client.
2017/12/14 12:20:11 [error] 21136#21136: *30412802 upstream prematurely closed connection while sending to client, client: 10.11.13.1, server: xxx.example.com, request: "GET /file-upload/jzaNGjvqD7k8uPHH9/jakUHCacKjIliP79yxJN.jpeg HTTP/1.1", upstream: "http://10.10.1.xxx:3000/file-upload/jzaNGjvqD7k8uPHH9/jakUHCacKjIliP79yxJN.jpeg", host: "xxx.example.com", referrer: "https://xxx.example.com/direct/userXX"
Rocket.Chat itself doesn't log any errors neither on uplaoding nor on the request.
Any suggestions where to look for?
@fadanner In order to investigate the issue, let me ask you a few questions:
- What method of upload is your server using?
- Does the URL is secured by SSL?
- Is the generated URL from mobile different than the one generated when you upload from desktop?
Thanks,
-
Server is using Filesystem upload
-
Server is secured with SSL between client and reverse proxy. Connection from reverse proxy to rocket.chat is unsecured.
-
The http-Urls looks the same for me: working image: https://xxx.example.com/file-upload/w9SLwG9X9jvwWhMMX/078EDBE7-45C4-4CCF-9C86-979E78E96D60.png broken image: https://xxx.example.com/file-upload/jzaNGjvqD7k8uPHH9/jakUHCacKjIliP79yxJN.jpeg
The first part of the url is random guid, the filenamepart is the generated filename. This is not the same, the app is using a random part here, too and it appends jpeg.
When i look into the data directory of the rocketchat server it is strange, that there is the jpeg extended, i think all with an extension here are the broken ones, but could not really test it for all.

Same problem here: Uploading a picture with the iOS client.
- In the browser client pictures are shown
- In the iOS App they are not
- In the Linux App they're also not
Version: 0.59.4 (Which seems to be actually 0.59.6) Storage Type: FileSystem
Can confirm that at least one Broken Picture has the .jpeg extension.
@mxmo0rhuhn @fadanner Can you guys give us access to your server (with a user) or give us a print screen of the exact same upload settings? We'll try to reproduce the issue.
Well access to our prod servers will not be possible - we would have to put some work into deploying a staging system if it's really needed.
For now: Our upload settings:

We're just having the same or at least similar issue. I searched through the mongodb and noticed a mismatch of file size and "size" param. In our case "size" in mongo is e.g. 333782 and in filesystem 112995 and Safari tries to download full 334K, which leads to Failed to load resource: Network connection was lost (Server sends EOF) and blank image (builds up image until real file size reached, then waits until the error reported and switches to "image could not be displayed").
File shows up in Rambox client without a problem. Seems like some browsers/clients ignore this and show the file downloaded so far.
The original image was 1997083B 3024x4032 jpg, Server saved file as 112995B 1024x1366 jpeg, tries to download as 333782B jpeg.
Chrome and FF seem to ignore the bigger (pretended) file size but still try to download as many bytes as the header says. So just Safari/Webkit (Mac + iOS) seem to respect the header information, which is why I saw the images just in my Rambox client (just using Safari/Rambox/RC+ iOS).
After updating MongoDB to reflect the real file size, all works fine!
Analysis of Filesizes
SIZE MISMATCH: MONGO 103667 - FS 29330 SIZE MISMATCH: MONGO 103667 - FS 29330 SIZE MISMATCH: MONGO 843472 - FS 384000 SIZE MISMATCH: MONGO 843472 - FS 384000 SIZE MISMATCH: MONGO 128660 - FS 43011 SIZE MISMATCH: MONGO 401760 - FS 180925 SIZE MISMATCH: MONGO 158451 - FS 75033 SIZE MISMATCH: MONGO 190593 - FS 76428 SIZE MISMATCH: MONGO 469538 - FS 189760 SIZE MISMATCH: MONGO 300708 - FS 123360 SIZE MISMATCH: MONGO 304329 - FS 145533 SIZE MISMATCH: MONGO 385197 - FS 130752 SIZE MISMATCH: MONGO 226542 - FS 88984 SIZE MISMATCH: MONGO 128956 - FS 45777 SIZE MISMATCH: MONGO 428377 - FS 165802 SIZE MISMATCH: MONGO 237150 - FS 86316 SIZE MISMATCH: MONGO 182542 - FS 82854 SIZE MISMATCH: MONGO 182542 - FS 82854 SIZE MISMATCH: MONGO 392665 - FS 140697 SIZE MISMATCH: MONGO 549776 - FS 216520 SIZE MISMATCH: MONGO 222073 - FS 102228 SIZE MISMATCH: MONGO 175973 - FS 50880 SIZE MISMATCH: MONGO 538672 - FS 200284 SIZE MISMATCH: MONGO 395724 - FS 156033 SIZE MISMATCH: MONGO 553070 - FS 220403 SIZE MISMATCH: MONGO 330323 - FS 111446 SIZE MISMATCH: MONGO 208276 - FS 72749 SIZE MISMATCH: MONGO 237746 - FS 74474 SIZE MISMATCH: MONGO 333630 - FS 123168 SIZE MISMATCH: MONGO 130069 - FS 61184 SIZE MISMATCH: MONGO 72373 - FS 33009 SIZE MISMATCH: MONGO 212477 - FS 72266 SIZE MISMATCH: MONGO 283368 - FS 131218 SIZE MISMATCH: MONGO 293963 - FS 100653 SIZE MISMATCH: MONGO 293963 - FS 100653 SIZE MISMATCH: MONGO 293963 - FS 100653 SIZE MISMATCH: MONGO 333782 - FS 112995 SIZE MISMATCH: MONGO 333782 - FS 112995 SIZE MISMATCH: MONGO 333782 - FS 112995 SIZE MISMATCH: MONGO 434765 - FS 182052 SIZE MISMATCH: MONGO 763831 - FS 312313
Python script to fix MongoDB entries
from pymongo import MongoClient
from glob import glob
import os
db_host = 'localhost'
db_port = 27017
db_name = 'rocketchat'
file_location = '/filesystem/uploads/location/'
client = MongoClient(db_host, db_port)
db = client[db_name]
uploads = db.rocketchat_uploads
for upload in uploads.find():
if upload['store'] != "FileSystem:Uploads":
continue
f = glob(file_location + upload['_id'] + '*')
if (len(f)):
size = os.path.getsize(f[0])
if size != upload['size']:
print("SIZE MISMATCH: MONGO %d - FS %d" % (upload['size'], size))
uploads.update_one(
{'_id': upload['_id']},
{'$set': {'size': size}}
)
@mxmo0rhuhn @fadanner Can you guys try to see if the solution of @soundstorm works for you, please?
Sadly due to our setup it is not that easy for us to perform this operation...
However the approach seems very promising!
This could be seen as an migration fix, for normal operation this must be run continously, which is not good for productive environments. Mid term fix: switch to GridFS (for single instance system not ideal, but GridFS seems to be unaffected) Long term fix: check the calculation and fix that in code.
@mxmo0rhuhn @soundstorm I'm investigating the issue here, looks like is something wrong in our back-end code. I'll return to you guys as soon as I have an answer.
@mxmo0rhuhn If you get the fileURL, append ?rc_user=(your_user_id)&rc_token=(your_token) does it work in the browser? I would love to have an example of URL that doesn't work in iOS but works on the browser.
@rafaelks Safari + iOS App: fail if filesize doesn't match Content-Length (trying to get more after EOF) Almost all other browsers discard the Content-Length if an EOF is received earlier. Send the link via mail or how? Including token in public is not the best ;-)
Otherwise I can give you credentials for a [bot+user] user at our system and send you an image.
@soundstorm Yes, send me over email: rafael.kellermann at rocket.chat
@rafaelks Login credentials in your inbox [check spam?]
@soundstorm @mxmo0rhuhn OK, I'll try something... are you guys in our TestFlight? If not, send me your email to rafael.kellermann at rocket.chat and then you guys can help me testing it.
Confirmed! Great! Now just a simple python script migration until the public release.
@soundstorm Amazing, thank you very much for your help on tests! 👍