sym 图片域名存储访问

程序修改

修改 symphony.properties 文件

upload.local.dir=/mnt/upload/

修改 AudioMgmtService.java

    public void removeAudioFile(final String audioURL) {
        try {
            LOGGER.log(Level.INFO, "Removing audio file [" + audioURL + "]");

            if (Symphonys.QN_ENABLED) {
                final Auth auth = Auth.create(Symphonys.UPLOAD_QINIU_AK, Symphonys.UPLOAD_QINIU_SK);
                final BucketManager bucketManager = new BucketManager(auth, new Configuration());
                final String fileKey = StringUtils.replace(audioURL, Symphonys.UPLOAD_QINIU_DOMAIN + "/", "");
                bucketManager.delete(Symphonys.UPLOAD_QINIU_BUCKET, fileKey);
            } else {
                /**
                 * create by: qiankunpingtai
                 * create time: 2019/4/16 10:34
                 * website:https://qiankunpingtai.cn
                 * description: 
                 * 修改本地文件通过绝对路径获取
                 * 在删除帖子的语音文件时,定位本地文件位置
                 */

//                final String fileName = StringUtils.replace(audioURL, Latkes.getServePath() + "/mnt/upload", "");
                final String fileName = StringUtils.replace(audioURL, "http://qkpt.top"+ "/mnt/upload", "");
                final File file = new File(Symphonys.UPLOAD_LOCAL_DIR + fileName);
                FileUtils.deleteQuietly(file);
            }

            LOGGER.log(Level.INFO, "Removed audio file [" + audioURL + "]");
        } catch (final Exception e) {
            if (e instanceof QiniuException) {
                try {
                    LOGGER.log(Level.ERROR, "Removes audio failed [" + audioURL + "], Qiniu exception body [" +
                            ((QiniuException) e).response.bodyString() + "]");
                } catch (final Exception qe) {
                    LOGGER.log(Level.ERROR, "Removes audio and parse result exception", qe);
                }
            } else {
                LOGGER.log(Level.ERROR, "Removes audio failed [" + audioURL + "]", e);
            }
        }
    }
    public String tts(final String text, final String type, final String textId, final String uid) {
        final byte[] bytes = baiduTTS(text, uid);
        if (null == bytes) {
            return "";
        }

        String ret;
        try {
            if (Symphonys.QN_ENABLED) {
                final Auth auth = Auth.create(Symphonys.UPLOAD_QINIU_AK, Symphonys.UPLOAD_QINIU_SK);
                final UploadManager uploadManager = new UploadManager(new Configuration());
                final BucketManager bucketManager = new BucketManager(auth, new Configuration());
                final String fileKey = "audio/" + type + "/" + textId + ".mp3";
                try {
                    bucketManager.delete(Symphonys.UPLOAD_QINIU_BUCKET, fileKey);
                } catch (final Exception e) {
                    // ignore
                }
                uploadManager.put(bytes, fileKey, auth.uploadToken(Symphonys.UPLOAD_QINIU_BUCKET), null, "audio/mp3", false);
                ret = Symphonys.UPLOAD_QINIU_DOMAIN + "/" + fileKey;
            } else {
                String fileName = UUID.randomUUID().toString().replaceAll("-", "") + ".mp3";
                fileName = FileUploadProcessor.genFilePath(fileName);
                try (final OutputStream output = new FileOutputStream(Symphonys.UPLOAD_LOCAL_DIR + fileName)) {
                    IOUtils.write(bytes, output);
                }
                /**
                 * create by: qiankunpingtai
                 * create time: 2019/4/16 10:34
                 * website:https://qiankunpingtai.cn
                 * description:
                 * 修改本地文件通过绝对路径获取
                 * 处理语音文件,返回语音文件所在的路径
                 */
                //ret = Latkes.getServePath() + "/mnt/upload/" + fileName;
                ret = "http://qkpt.top"+ "/mnt/upload/" + fileName;
            }

            return ret;
        } catch (final Exception e) {
            if (e instanceof QiniuException) {
                try {
                    LOGGER.log(Level.ERROR, "Uploads audio failed [type=" + type + ", textId=" + textId + "], Qiniu exception body [" +
                            ((QiniuException) e).response.bodyString() + "]");
                } catch (final Exception qe) {
                    LOGGER.log(Level.ERROR, "Uploads audio and parse result exception", qe);
                }
            } else {
                LOGGER.log(Level.ERROR, "Uploads audio failed [type=" + type + ", textId=" + textId + "]", e);
            }
        }

        return "";
    }

修改 UserMgmtService.java

if (Symphonys.QN_ENABLED) {
                            final Auth auth = Auth.create(Symphonys.UPLOAD_QINIU_AK, Symphonys.UPLOAD_QINIU_SK);
                            final UploadManager uploadManager = new UploadManager(new Configuration());

                            uploadManager.put(avatarData, "avatar/" + ret, auth.uploadToken(Symphonys.UPLOAD_QINIU_BUCKET),
                                    null, "image/jpeg", false);
                            user.put(UserExt.USER_AVATAR_URL, Symphonys.UPLOAD_QINIU_DOMAIN + "/avatar/" + ret + "?" + new Date().getTime());
                        } else {
                            String fileName = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg";
                            fileName = FileUploadProcessor.genFilePath(fileName);
                            new File(Symphonys.UPLOAD_LOCAL_DIR + fileName).getParentFile().mkdirs();
                            try (final OutputStream output = new FileOutputStream(Symphonys.UPLOAD_LOCAL_DIR + fileName)) {
                                IOUtils.write(avatarData, output);
                            }
                            /**
                             * create by: qiankunpingtai
                             * create time: 2019/4/16 10:34
                             * website:https://qiankunpingtai.cn
                             * description:
                             * 修改本地文件通过绝对路径获取
                             * 头像图片URL地址获取,用户新增时写入userAvatarURL字段
                             */
//                            user.put(UserExt.USER_AVATAR_URL, Latkes.getServePath()+ "/mnt/upload/" + fileName);
                            user.put(UserExt.USER_AVATAR_URL, "http://qkpt.top" + "/mnt/upload/" + fileName);
                        }
                    } catch (final IOException e) {
                        LOGGER.log(Level.ERROR, "Generates avatar error, using default thumbnail instead", e);

                        user.put(UserExt.USER_AVATAR_URL, AvatarQueryService.DEFAULT_AVATAR_URL);
                    }

修改 PostExportService.java

            if (Symphonys.QN_ENABLED) {
                final Auth auth = Auth.create(Symphonys.UPLOAD_QINIU_AK, Symphonys.UPLOAD_QINIU_SK);
                final UploadManager uploadManager = new UploadManager(new Configuration());
                uploadManager.put(zipData, fileKey, auth.uploadToken(Symphonys.UPLOAD_QINIU_BUCKET),
                        null, "application/zip", false);

                return Symphonys.UPLOAD_QINIU_DOMAIN + "/" + fileKey;
            } else {
                fileKey = FileUploadProcessor.genFilePath(fileKey);
                final String filePath = Symphonys.UPLOAD_LOCAL_DIR + fileKey;

                FileUtils.copyFile(zipFile, new File(filePath));
                /**
                 * create by: qiankunpingtai
                 * create time: 2019/4/16 10:34
                 * website:https://qiankunpingtai.cn
                 * description:
                 * 修改本地文件通过绝对路径获取
                 * 通过给定用户的id导出用户的所有帖子
                 */
//                return Latkes.getServePath() + "/mnt/upload/" + fileKey;
                return "http://qkpt.top"+  "/mnt/upload/" + fileKey;
            }
        } catch (final Exception e) {
            LOGGER.log(Level.ERROR, "Uploading exprted data failed", e);

            return null;
        }

修改 FileUploadProcessor.java

                if (QN_ENABLED) {
                    bytes = fileBytes.get(i);
                    final String contentType = file.getHeader().getContentType();
                    uploadManager.asyncPut(bytes, fileName, uploadToken, null, contentType, false, (key, r) -> {
                        LOGGER.log(Level.TRACE, "Uploaded [" + key + "], response [" + r.toString() + "]");
                        countDownLatch.countDown();
                    });
                    url = Symphonys.UPLOAD_QINIU_DOMAIN + "/" + fileName;
                    succMap.put(originalName, url);
                } else {
                    final Path path = Paths.get(Symphonys.UPLOAD_LOCAL_DIR, fileName);
                    path.getParent().toFile().mkdirs();
                    try (final OutputStream output = new FileOutputStream(path.toFile());
                         final InputStream input = file.getFileInputStream()) {
                        IOUtils.copy(input, output);

                        countDownLatch.countDown();
                    }
                    /**
                     * create by: qiankunpingtai
                     * create time: 2019/4/16 10:34
                     * website:https://qiankunpingtai.cn
                     * description:
                     * 修改本地文件通过绝对路径获取
                     */
//                    url = Latkes.getServePath() + "/mnt/upload/" + fileName;
                    url = "http://qkpt.top"+ "/mnt/upload/" + fileName;
                    succMap.put(originalName, url);
                }
            } catch (final Exception e) {
                LOGGER.log(Level.ERROR, "Uploads file failed", e);

                errFiles.add(originalName);
            }

修改 FetchUploadProcessor.java

        if (Symphonys.QN_ENABLED) {
            final Auth auth = Auth.create(Symphonys.UPLOAD_QINIU_AK, Symphonys.UPLOAD_QINIU_SK);
            final UploadManager uploadManager = new UploadManager(new Configuration());

            try {
                uploadManager.put(bytes, "e/" + fileName, auth.uploadToken(Symphonys.UPLOAD_QINIU_BUCKET),
                        null, contentType, false);
            } catch (final Exception e) {
                LOGGER.log(Level.ERROR, "Uploads to Qiniu failed", e);
            }

            data.put(Common.URL, Symphonys.UPLOAD_QINIU_DOMAIN + "/e/" + fileName);
            data.put("originalURL", originalURL);
        } else {
            fileName = FileUploadProcessor.genFilePath(fileName);
            try (final OutputStream output = new FileOutputStream(Symphonys.UPLOAD_LOCAL_DIR + fileName)) {
                IOUtils.write(bytes, output);
            } catch (final Exception e) {
                LOGGER.log(Level.ERROR, "Writes output stream failed", e);
            }
            /**
             * create by: qiankunpingtai
             * create time: 2019/4/16 10:34
             * website:https://qiankunpingtai.cn
             * description:
             * 修改本地文件通过绝对路径获取
             */
//            data.put(Common.URL, Latkes.getServePath()+ "/mnt/upload/" + fileName);
            data.put(Common.URL, "http://qkpt.top"+  "/mnt/upload/" + fileName);
            data.put("originalURL", originalURL);
        }

修改 nginx 配置

user  root;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
        map $http_upgrade $connection_upgrade {
                default upgrade;
                '' close;
        }
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location /mnt/{
                root   /;
                autoindex on;
        }
        location /symphony {
                proxy_pass http://localhost:8080/symphony;
                proxy_redirect default;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $connection_upgrade;
                proxy_set_header Host $host:$server_port;
                proxy_set_header REMOTE-HOST $remote_addr;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
      server {
        listen       80;
        server_name  qkpt.top;
        location /mnt/{
                root   /;
                autoindex on;
        }
        location /symphony {
                proxy_pass http://localhost:8080/symphony;
                proxy_redirect default;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $connection_upgrade;
                proxy_set_header Host $host:$server_port;
                proxy_set_header REMOTE-HOST $remote_addr;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
     }

    }
}

效果

图片.png