我有一个页面可以将文件上传到服务器。现在,由于我将文件存储在数据库中的类型为(bytea)的列中,因此我想知道如何在通过axios发送文件之前将该文件转换为blob数据.post。
FileUpload.vue
class ReturnProductInvoiceForm(ModelForm):
invoice_number = ModelChoiceField(queryset=InvoiceModel.objects.all())
class Meta:
model = ReturnInvoiceModel
fields = ['invoice_number']
class ReturnProductQuantityForm(ModelForm):
product = ModelChoiceField(queryset=Products.objects.all())
class Meta:
model = SelectQuantityReturnModel
fields = ['product','quantity','price']
def clean(self):
#i need to clean the form right here
#if invoice_number in `ReturnProductInvoiceForm` has not `product` then raise some error!
class TestClass
{
TestClass([string]$msg) {
Write-Host "Ctor sees: $msg"
}
TestMethod([string]$msg) {
Write-Host "TestMethod sees: $msg"
}
}
# this works:
$x = Get-Date
$test1 = [TestClass]::new($x)
# this also works:
$x = Get-Date
$test1.TestMethod($x)
# but doing the same thing inline is a syntax error: Missing ')' in method call.
$test2 = [TestClass]::new(Get-Date)
$test2 = [TestClass]::new(Get-Date())
$test1.TestMethod(Get-Date)
读取数组缓冲区并将其转换为二进制字符串
<template>
<div class="file">
<input type="file" @change="Images_onFileChanged">
</div>
</template>
<script>
export default {
name: 'FileUpload',
data () {
return {
selectedFile : null
}
},
methods: {
Images_onFileChanged (event) {
console.log('inside Images_onFileChanged '+event.target.files[0]);
console.log('inside Images_onFileChanged seassion id is'+this.$store.getters.getSessionData().key);
var sessionid= this.$store.getters.getSessionData().key;
var chosenfile=this.selectedFile = event.target.files[0];
this.$store.dispatch('uploadFile',{chosenfile,sessionid} );
}
}
}
</script>
使用当前代码后操作成功,但是在数据库中blob列值显示为null(请参见屏幕截图)。请帮助?我在这里做什么错了?
注意:将存储Blob的列类型为(bytea)类型。