小编joh*_*mon的帖子

Node.js获取文件扩展名

我在node.js中使用express 3创建文件上传功能.

我想抓取图像的文件扩展名.所以我可以重命名该文件,然后将文件扩展名附加到它.

app.post('/upload', function(req, res, next) {
    var is = fs.createReadStream(req.files.upload.path),
        fileExt = '', // I want to get the extension of the image here
        os = fs.createWriteStream('public/images/users/' + req.session.adress + '.' + fileExt);
});
Run Code Online (Sandbox Code Playgroud)

如何在node.js中获取图像的扩展名?

javascript file-type node.js

171
推荐指数
8
解决办法
16万
查看次数

我应该在调度时捕获 Redux promise 错误还是只在 reducer 中处理它?

所以基本上我正在使用 thunk 和 redux-promise-middleware 调度一个动作,这使得 API 调用返回一个承诺。然后我将返回的承诺作为“有效载荷”参数发送给另一个动作创建者,该参数与 redux-promise-middleware 一起使用并处理不同的动作 MY_ACTION_TYPE_PENDING 或 MY_ACTION_TYPE_REJECTED 或 MY_ACTION_TYPE_FULFILLED。我的问题是我是否通过 _REJECTED 操作处理 reducer 中的错误,而不是在我的 dispatch(actionCreator(payload)? _REJECTED ACTION 错误。

下面是我的一些操作:

export const RECEIVE_POSTS = 'RECEIVE_POSTS';
export const receivePosts = (data) => ({
    type: RECEIVE_POSTS,
    payload: data
})

// thunk middleware for fetching blog
                    export const fetchPosts = () => { 
                        return (dispatch) => {
                            const payload = contentfulClient.getEntries().then(
                                data => data.items,
                                error => console.log('An error occurred in fetchPost thunk middleware', error)
                                ) 
                            return dispatch(receivePosts(payload))
                            .catch((error) => { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs es6-promise redux redux-promise-middleware

5
推荐指数
1
解决办法
3349
查看次数

即使在客户端,是否有办法保护 React JS 中的 API 密钥?

在 React javascript 文件上使用 API 密钥时,是否有办法保护它的安全?例如;

emailjs.init("API_KEY");
Run Code Online (Sandbox Code Playgroud)

javascript client-side api-key reactjs

0
推荐指数
1
解决办法
1万
查看次数