Using DELETE cause 405 error while POST works in S3

I am trying to implement a image hosting function using AWS S3 and Hono for API endpoints with NextJS on top.
When I building a delete function, if I define the API on server as delete, it won’t work and produces 405 error. In contrast, using post won’t cause any issue and it works. But in my understanding, defining post, delete or put is required for semantic purposes.
Below is my implementation:
Server-side (Hono):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const mediaS3App = new Hono()
.delete('/delete', async (c) => {
try {
const fileName = c.req.query('fileName');
if (!fileName) {
return c.json({error: 'File name required.'}, 400)
}
const result = await getSignedURL(fileName, 'DELETE')
if (result.failure) {
return c.json({error: result.failure}, 401)
}
return c.json({url: result.success?.url})
} catch (error) {
console.error('Server error:', error);
return c.json({error: 'An unexpected error occurred.'}, 500)
}
})
</code>
<code>const mediaS3App = new Hono() .delete('/delete', async (c) => { try { const fileName = c.req.query('fileName'); if (!fileName) { return c.json({error: 'File name required.'}, 400) } const result = await getSignedURL(fileName, 'DELETE') if (result.failure) { return c.json({error: result.failure}, 401) } return c.json({url: result.success?.url}) } catch (error) { console.error('Server error:', error); return c.json({error: 'An unexpected error occurred.'}, 500) } }) </code>
const mediaS3App = new Hono()
.delete('/delete', async (c) => {
        try {
            const fileName = c.req.query('fileName');

            if (!fileName) {
                return c.json({error: 'File name required.'}, 400)
            }

            const result = await getSignedURL(fileName, 'DELETE')

            if (result.failure) {
                return c.json({error: result.failure}, 401)
            }
            return c.json({url: result.success?.url})
        } catch (error) {
            console.error('Server error:', error);
            return c.json({error: 'An unexpected error occurred.'}, 500)
        }
    })

Client-side:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>await Promise.all(fileSelected.map(async (fileName) => {
try {
const DELURLResponse = await fetch(`/api/media/delete?fileName=${encodeURIComponent(fileName)}`, {
method: 'DELETE',
});
const DELSignedURL = await DELURLResponse.json();
if (DELURLResponse.ok && DELSignedURL.url) {
const deleteResponse = await fetch(DELSignedURL.url, {
method: 'DELETE',
});
if (deleteResponse.ok) {
console.log('delete successful')
mutationDelMediaDb.mutate(fileName)
} else {
console.log('error on deletetion')
}
} else {
console.error('Failed to delete, something wrong with delete presigned URL', DELSignedURL.error);
}
} catch (error) {
console.error('An error occurred during the deletion:', error);
}
}))
</code>
<code>await Promise.all(fileSelected.map(async (fileName) => { try { const DELURLResponse = await fetch(`/api/media/delete?fileName=${encodeURIComponent(fileName)}`, { method: 'DELETE', }); const DELSignedURL = await DELURLResponse.json(); if (DELURLResponse.ok && DELSignedURL.url) { const deleteResponse = await fetch(DELSignedURL.url, { method: 'DELETE', }); if (deleteResponse.ok) { console.log('delete successful') mutationDelMediaDb.mutate(fileName) } else { console.log('error on deletetion') } } else { console.error('Failed to delete, something wrong with delete presigned URL', DELSignedURL.error); } } catch (error) { console.error('An error occurred during the deletion:', error); } })) </code>
await Promise.all(fileSelected.map(async (fileName) => {
            try {
                const DELURLResponse = await fetch(`/api/media/delete?fileName=${encodeURIComponent(fileName)}`, {
                    method: 'DELETE',
                });

                const DELSignedURL = await DELURLResponse.json();
                if (DELURLResponse.ok && DELSignedURL.url) {
                    const deleteResponse = await fetch(DELSignedURL.url, {
                        method: 'DELETE',
                    });
                    if (deleteResponse.ok) {
                        console.log('delete successful')
                        mutationDelMediaDb.mutate(fileName)
                    } else {
                        console.log('error on deletetion')
                    }
                } else {
                    console.error('Failed to delete, something wrong with delete presigned URL', DELSignedURL.error);
                }
            } catch (error) {
                console.error('An error occurred during the deletion:', error);
            }
        }))

I got the following error in the console:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>FileUpload.tsx:190
DELETE http://localhost:3000/api/media/delete?fileName=f7a7b24e-b721-4e51-a416-af0c82258bf7-458615387_1052344776416616_1974440516975429873_n.JPEG 405 (Method Not Allowed)
eval @ FileUpload.tsx:190
deleteOnS3 @ FileUpload.tsx:188
deleteFile @ display-image.tsx:69
callCallback @ react-dom.development.js:20565
invokeGuardedCallbackImpl @ react-dom.development.js:20614
invokeGuardedCallback @ react-dom.development.js:20689
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:20703
executeDispatch @ react-dom.development.js:32128
processDispatchQueueItemsInOrder @ react-dom.development.js:32160
processDispatchQueue @ react-dom.development.js:32173
dispatchEventsForPlugins @ react-dom.development.js:32184
eval @ react-dom.development.js:32374
batchedUpdates$1 @ react-dom.development.js:24953
batchedUpdates @ react-dom.development.js:28844
dispatchEventForPluginEventSystem @ react-dom.development.js:32373
dispatchEvent @ react-dom.development.js:30141
dispatchDiscreteEvent @ react-dom.development.js:30112
Show 14 more frames
Show lessUnderstand this error
FileUpload.tsx:209 An error occurred during the deletion: SyntaxError: Unexpected end of JSON input
at eval (FileUpload.tsx:194:59)
at async Promise.all (index 0)
at async deleteOnS3 (FileUpload.tsx:188:9)
</code>
<code>FileUpload.tsx:190 DELETE http://localhost:3000/api/media/delete?fileName=f7a7b24e-b721-4e51-a416-af0c82258bf7-458615387_1052344776416616_1974440516975429873_n.JPEG 405 (Method Not Allowed) eval @ FileUpload.tsx:190 deleteOnS3 @ FileUpload.tsx:188 deleteFile @ display-image.tsx:69 callCallback @ react-dom.development.js:20565 invokeGuardedCallbackImpl @ react-dom.development.js:20614 invokeGuardedCallback @ react-dom.development.js:20689 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:20703 executeDispatch @ react-dom.development.js:32128 processDispatchQueueItemsInOrder @ react-dom.development.js:32160 processDispatchQueue @ react-dom.development.js:32173 dispatchEventsForPlugins @ react-dom.development.js:32184 eval @ react-dom.development.js:32374 batchedUpdates$1 @ react-dom.development.js:24953 batchedUpdates @ react-dom.development.js:28844 dispatchEventForPluginEventSystem @ react-dom.development.js:32373 dispatchEvent @ react-dom.development.js:30141 dispatchDiscreteEvent @ react-dom.development.js:30112 Show 14 more frames Show lessUnderstand this error FileUpload.tsx:209 An error occurred during the deletion: SyntaxError: Unexpected end of JSON input at eval (FileUpload.tsx:194:59) at async Promise.all (index 0) at async deleteOnS3 (FileUpload.tsx:188:9) </code>
FileUpload.tsx:190 
        
        
       DELETE http://localhost:3000/api/media/delete?fileName=f7a7b24e-b721-4e51-a416-af0c82258bf7-458615387_1052344776416616_1974440516975429873_n.JPEG 405 (Method Not Allowed)
eval @ FileUpload.tsx:190
deleteOnS3 @ FileUpload.tsx:188
deleteFile @ display-image.tsx:69
callCallback @ react-dom.development.js:20565
invokeGuardedCallbackImpl @ react-dom.development.js:20614
invokeGuardedCallback @ react-dom.development.js:20689
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:20703
executeDispatch @ react-dom.development.js:32128
processDispatchQueueItemsInOrder @ react-dom.development.js:32160
processDispatchQueue @ react-dom.development.js:32173
dispatchEventsForPlugins @ react-dom.development.js:32184
eval @ react-dom.development.js:32374
batchedUpdates$1 @ react-dom.development.js:24953
batchedUpdates @ react-dom.development.js:28844
dispatchEventForPluginEventSystem @ react-dom.development.js:32373
dispatchEvent @ react-dom.development.js:30141
dispatchDiscreteEvent @ react-dom.development.js:30112
Show 14 more frames
Show lessUnderstand this error
FileUpload.tsx:209 An error occurred during the deletion: SyntaxError: Unexpected end of JSON input
    at eval (FileUpload.tsx:194:59)
    at async Promise.all (index 0)
    at async deleteOnS3 (FileUpload.tsx:188:9)

It would work If I change to route to post

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>.post('/delete', async (c) => {
...
</code>
<code>.post('/delete', async (c) => { ... </code>
.post('/delete', async (c) => {
...
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> await Promise.all(fileSelected.map(async (fileName) => {
try {
const DELURLResponse = await fetch(`/api/media/delete?fileName=${encodeURIComponent(fileName)}`, {
method: 'POST',
});
...
</code>
<code> await Promise.all(fileSelected.map(async (fileName) => { try { const DELURLResponse = await fetch(`/api/media/delete?fileName=${encodeURIComponent(fileName)}`, { method: 'POST', }); ... </code>
 await Promise.all(fileSelected.map(async (fileName) => {
            try {
                const DELURLResponse = await fetch(`/api/media/delete?fileName=${encodeURIComponent(fileName)}`, {
                    method: 'POST',
                });
...

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật