-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Uploaded images become inaccessible after the domain was changed. #861
Comments
Thanks for the feedback. It seems that the storing avatars relies on absolute paths. Modifying it to a new domain could potentially introduce new issues. Saving them as relative paths might be a better option. 🤔 |
@LinkinStars
|
@LinkinStars I found that all images in a question, answer or avatar have this issue. I've changed the issue title. |
I would like to solve this issue once the solution is settled. 👀 |
Fwiw, I ran into this issue with logo and favicon as well under the branding settings when originally testing how to go about setting up answer. |
@Octobug Your suggestion is great. We have carefully discussed this issue for some time and believe that providing a command-line solution would be better. For example, we can offer a functionality like this: ./answer fix image from A to B This command can modify the domain name in existing data. The reasons for this are as follows:
Additionally, there is another requirement. We believe it would be helpful to provide an environment variable, Once again, thank you very much for suggesting this feature because we believe it could pose a little big challenge. What do you think? If there are any unclear points, we can continue the discussion. |
@LinkinStars Thank you for your detailed response! I am also in favor of building this functionality as a And let's split a URL into 2 major parts for the convenience in describing:
I think the There are 2 major types of uploaded files:
Pseudocode: // When fetching existing data to rewrite:
getImageURL(image) {
if (isLocalFile(image)) { // an image has a property to be distinguished. e.g. !startsWith('http')
return IMAGE_PATH_PREFIX + image.path;
} else {
return image.path;
}
}
Update: for files stored in external places, these args are needed.
Update:
|
This task seems heavy for a Go & Answer beginner (exactly me 🤣). If the coding job is real complicated under your estimation, I think it's better be done by your team. |
I agree.
That's a good summary. You got it.
Take it easy. You can try your best, and we will help you solve any problems together. 💪 |
@LinkinStars Okay then, I'll give it another try. |
I have another thought on external storage type... If the uploads dataset is huge, the migration could be very time-consuming because it needs to query & filter out all urls of avatars and urls in texts of questions & answers, and then write them back to DB. What if Answer saves all types of uploads with relative paths with a prefix marker? Like:
The default value of If the admin adds an external storage, since there is a Let's say there is a new type of {
"url_prefix_versions": {
"0": {
// ":0:/uploads/post/57pxxvykQFj.jpeg"
"active": true,
"value": "/"
},
"1": {
// ":1:/uploads/post/57pxxvykQFj.jpeg"
"active": false,
"value": "https://s3.east-1.xxx.com/"
},
"2": {
// ":2:/uploads/post/57pxxvykQFj.jpeg"
"active": true,
"value": "https://abc.oss-cn-hangzhou.aliyuncs.com/"
},
...
},
// other properties...
} With this solution, those relative paths hardly need to be changed. The basic migrate operation process is:
And still, However, migration of large dataset may not be common. The consideration here is whether it is worth implementing such a feature to address a rare scenario. If this idea is rejected, I will try to implement the previously discussed solution. |
@Octobug First of all, thank you very much for presenting the new proposal. We have had a detailed discussion regarding your proposal. It is certain that using external storage for migration would make it somewhat easier. However, we still have some considerations:
Therefore, based on the reasons stated above, we would prefer to keep the process simple, and thus we suggest sticking with the previous solution would be better. |
@LinkinStars Okay, it was just a thought. 👀 I would like to confirm some details: The env varDoes this var need to be supported both in Config File and Environment Variable?
It actually affects all kinds of uploads, so I think The command./answer fix upload PREFIX_SRC PREFIX_DST |
I can't agree more. 👍 Yes, supported both in config file and env would be better. So |
@LinkinStars I made some attempts on the var part. The consideration you mentioned before (I made it bold & italic) seemd hard to achieve: The var (
If using a symlink pointing to the locally moved uploaded files is acceptable (tell admins to do so in the documentation), the var seems to be unnecessary at all. Answer is able to distinguish these two types of uploads without an env var:
|
@Octobug 🤔 I got it. So, for now, we can consider only three scenarios:
|
Right, there are three scenarios for now. But scenario |
@Octobug 👍 What you said is absolutely correct. We are indeed concerned about the existence of such users. As far as I know, there are users who deploy their frontend and backend separately, and as you mentioned, images are accessed through |
@LinkinStars Okay, thank you for your patience! In this case, it seems that your first solution is better. :D That is, make the var a
|
@Octobug 😄 Maybe we can use |
@LinkinStars Aha, okay. I'll submit a PR a few days later together with the |
@LinkinStars Here's my version of the
When the fix command starts, it checks if there is a tmp file:
Switches:
Updated at 2024-07-17 22:40 It makes little sense to lock a data row no matter it's an online or offline fix. Because you cannot make sure that there aren't any web UI editors opened with old data loaded in it. Even after an offline fix is finished, there might still be a user going to submit the old version data. So, neither way is perfect. This corner case can only be addressed by the documentation work I guess. |
@Octobug Very thoughtful consideration. I have only one suggestion. I recommend that this command be run offline, but it's not mandatory. It would be advisable to include instructions in the documentation, suggesting users to run it offline. Otherwise, it would require handling various unexpected concurrency situations, such as table locking, which would make the implementation more complex. 🤔️ |
Okay. I have the feeling that I will give up the |
Describe the bug
Uploaded images become inaccessible after the domain was changed. I only tested it in development env.
To Reproduce
Steps to reproduce the behavior:
domain.old
, you uploaded your custom avatar.domain.old
todomain.new
, and the uploaded avatar became inaccessible.Expected behavior
Uploaded files should serve well no matter what the domain is.
Screenshots
Platform
The text was updated successfully, but these errors were encountered: