微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在解析服务器中保存文件?

如何解决如何在解析服务器中保存文件?

我有一个运行 parse-server: 2.8.4parse: 1.11.1 的基本解析服务器。我已将服务器连接到最近使用 appIdmasterKey 创建的 MongoDB Atlas 集群。

我还使用最新的解析 SDK 创建了一个 angular 应用程序。我为我在 parseService 中发送的文件添加一个 input

async onFileSelected(event: any) {
    const id = this.route.snapshot.paramMap.get('id');
    const file = event.target.files[0];

    this.parse
      .uploadPhoto(id,'photo',file)
      .then(() => {
        console.log('successfully uploaded photo');
      })
      .catch((err) => {
        console.log(err);
      });
  }

这是 parseService 函数

async uploadPhoto(id: string,fieldName: string,file: any): Promise<any> {
    const parseFile = new Parse.File(file.name,file);
    const Landmarks = Parse.Object.extend('Landmarks');
    const query = new Parse.Query(Landmarks);
    const landmark = await query.get(id);

    await parseFile.save();
    await landmark.set(fieldName,parseFile);
  }

我对解析服务器有其他请求以获取、保存或授权用户,一切正常,但是当我选择一个文件并将其发送为这样保存时。我从服务器收到 400 代码错误错误消息:error: Could not store file. code=130,message=Could not store file.

我进行了一些研究以找到解决方案,一个常见的问题是数据库中没有剩余空间。我的数据库基本上是空的,仍然有空间,而我试图保存的 jpeg 并没有那么大。我还检查了我的图集集群,似乎即使我收到错误,也有一个名为 fs.chunks 的集合,但是当我检查解析仪表板时,那里什么也没有。

我更喜欢一种解决方案,如果它存在,我不必更改我的解析服务器版本,但任何解决方案都适用于我,如果我遗漏了任何信息,请询问并提供它。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。