javascript - 在 React 中使用 Form.File 时找不到文件
问题描述
我正在尝试使用他们在 React 中的 API 将视频上传到 Vimeo。我有以下内容:
import React, { useEffect } from 'react';
import { Card, Container, Button, Form } from 'react-bootstrap';
import { vimeoClient } from '../../vimeo';
import { useState } from 'react';
const VideoUpload = () => {
const [fileName, setFileName] = useState();
const uploadHandler = e => {
e.preventDefault()
console.log(fileName);
vimeoClient.upload(
fileName,
{
'name': 'TEST TEST',
'description': 'TEST DESC'
},
function (uri) {
console.log('Your video URI is: ' + uri);
},
function (bytes_uploaded, bytes_total) {
var percentage = (bytes_uploaded / bytes_total * 100).toFixed(2)
console.log(bytes_uploaded, bytes_total, percentage + '%')
},
function (error) {
console.log('Failed because: ' + error)
}
);
};
return (
<Container
className="d-flex flex-column mt-5 justify-content-center align-items-center"
>
<Card className="w-100" style={{ maxWidth: "400px" }}>
<Card.Body>
<h2 className="text-center mb-4">Video Upload</h2>
<Form onSubmit={uploadHandler}>
<Form.Group className="mb-4" id="file">
<Form.Label>File</Form.Label>
<Form.File type="file" required onChange={ e => setFileName(e.target.files[0].name) } />
</Form.Group>
<Button className="w-100" variant="dark" type="submit">
Upload
</Button>
</Form>
</Card.Body>
</Card>
</Container>
);
};
export default VideoUpload;
Vimeo
api 需要path_to_a_video_on_the_file_system
作为参数,这里我使用的是fileName
. 但是,当我调用 API 时出现错误Failed because: Unable to locate file to upload.
看来我没有正确获得路径。如何使用 获取视频的路径Form.File
?
解决方案
推荐阅读
- javascript - 如何在“现在打牌”中显示音乐专辑封面?
- rest - 使用 NODE.js REST 后端所需的 VUEX
- java - 与 Java 相关的一致的“访问被拒绝”错误
- jquery - Node.js 在页面加载时发布请求
- php - 无法在同一页面中回显用户名?
- reactjs - React 测试库:想了解 container 和 document.body 的区别
- windows - PowerShell 从 WmiEvent (System.Management.ManagementEventWatcher) 获取详细的事件信息
- refactoring - 为什么“程序类”是一种设计气味?
- julia - 在 Julia 中哪里可以找到函数的签名?
- python - 如何在 Discord 机器人项目中运行额外的 Python 代码