Rocket.chat: Error when upload file to Rocket Chat in subfolder

Created on 29 Apr 2016  ·  28Comments  ·  Source: RocketChat/Rocket.Chat

Your Rocket.Chat version: 0.28 (make sure you are running the latest)

Hi,
I have some problem with Rocket Chat in subfolder

  • I can chat via web but can't access via App on Mobile
  • When I upload any file, it can't display with Image, text,.. and I can't download it too.
    Can you help me resolv them ?

This is error when i upload a photo.
1

file sharing subdir bug

Most helpful comment

Im taking a stab at this..

All 28 comments

What are your file upload settings?

I have same issue with images uploaded, please fix in next version.

My rocket.chat version: 0.29

Thank you very much!

image

Sorry @marceloschmidt ,
I have had a holiday recently so I can't reply to you.
I don't change any setting in Rocket Chat server. It is default setting.
I found it have some problem with link of file upload, it isn't behind subfolder.
I think it shoud be .../chat/file-upload/

Here is my setting:
1

This issue is file uploaded not run in sub directory like main page:

image

image

Please help me :(

@dangkiena3 using in a subdirectory is a very new addition, not many people are using it yet. So we're still working out the kinks. Bare with us

@geekgonecrazy many thank for reply. I'm still wait...

Same my issue, +1

Now version 0.31 still does not fix this issue :(

Version 0.32 still...

Now is 0.33 version, please help me

Yup, having the same problem.

Is there a way I could hack this temporarily by hard-coding my subfolder somewhere?

@SQUIDwarrior:

Why not temporarily "solve" the issue by creating a simple rewrite rule? It should be quite easy depending on what web server you're running.

[EDIT: Actually, forget my suggestion. It was just a thought and it could be done if you were really desperately needing it to at least momentarily work — until the issue is solved. I am fully aware that my suggestion is far from perfect or ideal.]

@k0nsl - No, that's a good workaround actually. I will give that a try! I totally didn't think of using a rewrite rule

[EDIT: Nope, that doesn't seem to work either. Guess I'll have to disable file uploads until this is fixed]

Still present with v0.34.

Im taking a stab at this..

@AlecTroemel awesome, all yours! 👍 Let us know how it goes. Feel free to open a PR if you need us to take a look at what you have. PR's are great for discussing in context of the code :smile:

same problem here :cry:

by changing https://github.com/AlecTroemel/Rocket.Chat/blob/develop/packages/rocketchat-message-attachments/client/messageAttachment.coffee#L11 to

return RocketChat.settings.get('Site_Url').replace(/\/$/, '') + url

rocketchat was able to find the image when being behind an nginx reverse proxy. However there is another (deeper) bug where it gives a 403 error on trying to get the image. this is because https://github.com/AlecTroemel/Rocket.Chat/blob/develop/lib/fileUpload.coffee#L16 is getting null for

Meteor._localStorage.getItem('Meteor.loginToken');

This value is needed to find an user and verify that they are able to see the image here https://github.com/AlecTroemel/Rocket.Chat/blob/develop/packages/rocketchat-file-upload/server/lib/requests.js#L30

This can be worked around by setting _Administration --> File Upload --> Protect uploaded files_ to false... though anyone can go and see those images..

@AlecTroemel what if you use Meteor.absoluteUrl() instead of RocketChat.settings.get('Site_Url'), would that solve it?

@marceloschmidt unfortunately (at least in my instance of rocketchat) Meteor.absoluteUrl() does not include the subdirectory. for example I've confirmed that the ROOT_URL env variable contains the full url with subdir http://mydomain.com/subdir, but Meteor.absoluteUrl() will only return http://mydomain.com/. Interestingly the ROOT_URL_PATH_PREFIX env var is undefined..which I think may be related to this problem

So it was my fault that ROOT_URL_PATH_PREFIX (I was trying to print it out before it was defined). From what I can tell, meteor takes the full url and splits it if there is the subdirectory.

So http://mydomain.com/subdir leads to

absoluteUrl = http://mydomain.com/
__meteor_runtime_config__.ROOT_URL_PATH_PREFIX = /subdir

When the meteor account login sees that there is a ROOT_URL_PATH_PREFIX it adds some namespace information to the Meteor.loginToken localstorage variable name (code here https://github.com/meteor/meteor/blob/master/packages/accounts-base/localstorage_token.js#L100)
so if there is a subdir, the loginToken key name changes, and this line will fail https://github.com/RocketChat/Rocket.Chat/blob/develop/lib/fileUpload.coffee#L16

heres an example of how those keys look for me
screen shot 2016-07-05 at 4 12 39 pm
I assume that ":/:/subdir" is the pattern, but I'm not 100% sure

The following things solved the issue for me:

return Meteor.absoluteUrl().replace(/\/$/, '') + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + url

I will make a PR so that others can review this.

This issue was resolved! Thank you very much!

But I still can't use Mobile App with sub dir

@AlecTroemel

Is #4014 related to this issue.

My userw gets the same issue but they we are not running in subdir,
However we have a nginx infront of the RC.

Was this fix in 0.37 released yesterday

@lunitic this fix was added in version 0.36

I find this issue in 0.49.3 . It is not fixed in 0.49.3 😢

The issue is open here #4832

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zeigerpuppy picture zeigerpuppy  ·  3Comments

sta-szek picture sta-szek  ·  3Comments

royalaid picture royalaid  ·  3Comments

mddvul22 picture mddvul22  ·  3Comments

danpospisil picture danpospisil  ·  3Comments