-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
Description
Capacitor Version
Latest Dependencies:
@capacitor/cli: 6.1.1
@capacitor/core: 6.1.1
@capacitor/android: 6.1.1
@capacitor/ios: 6.1.1
Installed Dependencies:
@capacitor/cli: 6.1.1
@capacitor/core: 6.1.1
@capacitor/android: 6.1.1
@capacitor/ios: 6.1.1
Other API Details
No response
Platforms Affected
- iOS
- Android
- Web
Current Behavior
axios
request with Content-Type: "multipart/form-data"
is not working. It doesn't send neither Content-Length
, Content-Type
no content itself.
It happens when CapacitorHttp
plugin is enabled.
I have a simple form allowing uploading files.
<input
title="Attach files"
type="file"
accept="image/*"
multiple
onChange={handleChange}
/>
and handler
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
const files = event.target.files;
const fileFirst = files?.item(0)
if (!fileFirst) return
const formData = new FormData();
formData.append('file', fileFirst);
const response = await axios.post('/api/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data',
}
});
console.log('File uploaded successfully:', response.status);
};
capacitor.config.ts
import { CapacitorConfig } from "@capacitor/cli";
const config: CapacitorConfig = {
// ....
plugins: {
CapacitorHttp: {
enabled: true,
},
// ...
},
};
export default config;
Expected Behavior
axios should work no matter if CapacitorHttp
enabled or not
Project Reproduction
Additional Information
No response
fobaz, gyto23, dhaval-rathod-deel, davideramoaxa, Azat8 and 3 more