ソースを参照

fix images url for messages

serg1557733 1 年間 前
コミット
07a9bfc27a

+ 2 - 1
backend/app.js

@@ -54,7 +54,6 @@ const getOneUser = async (userName) => {
     return userInDb;
 }
 app.post('/login', async (req, res) => {
-
     try {
         const {userName,password} = req.body;
         if (!isValidUserName(userName)){
@@ -125,6 +124,8 @@ app.post('/avatar', async (req, res) =>  {
 })
 
 app.post('/files', async (req, res) =>  {
+    console.log(req)
+
     if (!req.files || Object.keys(req.files).length === 0) {
         return res.status(400).json('No files were uploaded.');
     }  

+ 3 - 2
frontend/src/components/chatPage/messageForm/MessegaForm.jsx

@@ -120,7 +120,8 @@ export const MessageForm = () => {
 
                             <div style={{'display': 'flex', 'alignItems': 'center'}} >
 
-                                <a href={SERVER_URL + item.file} download> 
+                                <a href={SERVER_URL + '/' +item.file} download> 
+                                {console.log(SERVER_URL + '/' +item.file)}
                                     <Button
                                         variant="contained" 
                                         component="label"
@@ -147,7 +148,7 @@ export const MessageForm = () => {
                         { 
                             (item.file && item.fileType && item.fileType.split('/')[0] == 'image' ) //need to fix for other type files
                             ? 
-                                <img width={'auto'} height={350} src={ SERVER_URL + item.file} alt={'error load image'}/>
+                                <img width={'auto'} height={350} src={ SERVER_URL + '/' + item.file} alt={'error load image'}/>
                             :
                             ''
                         }

+ 4 - 4
frontend/src/reducers/messageReducer.js

@@ -48,10 +48,10 @@ export const fileMessage = createAsyncThunk(
             }
             formData.append('token', token)
             const response = await axios.post(POST_FILES_URL, formData,{
-                onUploadProgress: (progress) => {
-                    const {loaded, total} = progress;
-                    const persentage = Math.floor(loaded * 100 / total);
-                },
+                // onUploadProgress: (progress) => {
+                //     const {loaded, total} = progress;
+                //     const persentage = Math.floor(loaded * 100 / total);
+                // },
                     headers: {
                       "Content-type": "multipart/form-data",
                     }