将数据追加到FormData()时为null

时间:2019-05-14 15:30:48

标签: vue.js

我在vue上有这样的数据结构

data: {
   name: 'Lorem',
   status: 'Active',
   username: 'user-01',
   password: '12345'
},

然后我附加到FormData(),因为我想像这样将blob数据(图像)发送到服务器

let formData = new FormData(this.data); // my data
formData.append('photo', this.blob);

我使用axios,发送了图像但没有发送数据,当我在控制台上显示formData.entries()时,结果是

photo, [object File]

我该如何解决?谢谢

1 个答案:

答案 0 :(得分:1)

Rembermer FormData没有将JSON数据作为参数的构造方法。

尝试一下

2019-05-17 08:26:10,532 INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181] server.NIOServerCnxnFactory: Accepted socket connection from /127.0.0.1:54376
2019-05-17 08:26:10,538 INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181] server.ZooKeeperServer: Client attempting to establish new session at /127.0.0.1:54376
2019-05-17 08:26:10,565 INFO  [SyncThread:0] server.ZooKeeperServer: Established session 0x16ac32c6a8a0009 with negotiated timeout 40000 for client /127.0.0.1:54376
2019-05-17 08:26:13,917 INFO  [ProcessThread(sid:0 cport:2181):] server.PrepRequestProcessor: Processed session termination for sessionid: 0x16ac32c6a8a0009
2019-05-17 08:26:13,962 WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181] server.NIOServerCnxn: caught end of stream exception
EndOfStreamException: Unable to read additional data from client sessionid 0x16ac32c6a8a0009, likely client has closed socket
        at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:239)
        at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:203)
        at java.lang.Thread.run(Thread.java:748)
2019-05-17 08:26:13,962 INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181] server.NIOServerCnxn: Closed socket connection for client /127.0.0.1:54376 which had sessionid 0x16ac32c6a8a0009
2019-05-17 08:26:14,069 INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181] server.NIOServerCnxnFactory: Accepted socket connection from /127.0.0.1:54396
2019-05-17 08:26:14,073 INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181] server.ZooKeeperServer: Client attempting to establish new session at /127.0.0.1:54396
2019-05-17 08:26:14,110 INFO  [SyncThread:0] server.ZooKeeperServer: Established session 0x16ac32c6a8a000a with negotiated timeout 40000 for client /127.0.0.1:54396
2019-05-17 08:26:15,596 WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181] server.NIOServerCnxn: Exception causing close of session 0x16ac32c6a8a000a due to java.io.IOException: An existing connection was forcibly closed by the remote host
2019-05-17 08:26:15,596 INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181] server.NIOServerCnxn: Closed socket connection for client /127.0.0.1:54396 which had sessionid 0x16ac32c6a8a000a