如何创建“上传”带有 web2py 的文件
我有一个在 web2py 上运行的应用程序。对于这个应用程序,我想为每个用户将大量文件存储到数据库中,他们可以从自己的计算机上传这些文件,也可以在线创建并保存这些文件。这些文件可以是文本或二进制文件,但如果它们是在我的应用程序中创建的,它们将是文本。因此,我必须处理两种文件传入方式:
1)通过表单上传。数据库有一个“上传”类型的“文件”字段,我使用它进行存储:
db.allfiles.insert(filename=filename, \
file=db.allfiles.file.store(file.file,filename),user=me)
这会在上传目录中创建一个文件,该文件的名称附加有唯一的字符串。这个解决方案非常简单。
2) 我还需要存储通过 JSON 调用作为字符串传入的文件。我不确定如何创建“上传”类型文件并在上传目录中为它们指定唯一的名称。任何人都可以提供任何见解吗?
谢谢
I have an app running on web2py. For this app I want to store a lot of files to a database for each user, which they can either upload from their own computer or they can create online and save. These files can be either text or binary files, but if they are created in my app, they will be text. So I have 2 ways files come in that I have to handle:
1) Uploads through a form. The database has a "file" field of type "upload" which I store using:
db.allfiles.insert(filename=filename, \
file=db.allfiles.file.store(file.file,filename),user=me)
This creates a file with a unique string attached to its name in the uploads directory. This solution is pretty easy.
2) I also need to store files that come in as strings via JSON call. I am not sure how to create "upload" type files and give them unique names in the uploads directory. Can anyone give any insight?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以只输入传入的数据,将其转换为内存中的流并存储它,就像你在 1) 中所做的那样
I think you can just the incoming data, turn it into an in-memory stream and store it like you do at 1)