weixin_33705053 2017-06-04 14:33 采纳率: 0%
浏览 27

包含%的网址无法访问api

Hi trying to get a signUrl from S3, for some reason making the call with % isn't parse correctly by my code. I get a 404 not found.

This is the ajax request:

https://stage.musicmarkers.com/website/api/admin/get-signed-url/thumbnail/magazine%2F2BE.gif/image%2Fgif

My API:

app.get('/website/api/admin/get-signed-url/thumbnail/:key/:type', auth.getMember, directives.noCache, getThumbnailSingedUrl);

My function:

function getThumbnailSingedUrl(req, res) {

    if (!isAdmin(req, res)) {
        return;
    }

    var key = req.params.key || '';
    var type = req.params.type || '';

    ThumbnailBucketFacade.getSignedUrl(
        'putObject',
        key,
        type,
        function onGotSignedUrl(error, result) {
            if (error) {
                RestResponse.serverError(res, error);
            } else {
                RestResponse.ok(res, result);
            }
        }
    );
}

Making the call in a dev environment works.

Making the call without % environment works.

Same code exactly in a different project works.

Any ideas?

  • 写回答

2条回答 默认 最新

  • weixin_33719619 2017-06-04 14:55
    关注

    I believe what you have is encoded URI. So you need to decode it before using it:

    const key = req.params.key && decodeURIComponent(req.params.key) || '';
    const type = req.params.type && decodeURIComponent(req.params.type) || '';
    

    More on decoreURIComponent here.

    This is also backward compatible, so you don't have to worry that a plain string will get mangled.

    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划