问题
I've been experiencing behaviour on, at least my iPhone 6 Plus, when using the <input type="file">
to let the user upload an image.
<div class="add__from-camera">
<button class="add__from-camera__btn">
<i class="fa fa-fw fa-camera"></i> Add with Camera
</button>
<input class="add__from-camera__input" type="file">
</div>
This rest case results in crashes of the tab about 50% of the time, and in my app about 90% of the time.
I was 'lucky' enough to get all of Safari to crash once when the error happened, and this was part of the log:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00030000006467ba
Triggered by Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 WebKit 0x000000018a48566c WebKit::WebPageProxy::didChooseFilesForOpenPanelWithDisplayStringAndIcon(WTF::Vector<WTF::String, 0ul, WTF::CrashOnOverflow> const&, WTF::String const&, API::Data const*) + 44
1 WebKit 0x000000018a461648 WebKit::WebOpenPanelResultListenerProxy::chooseFiles(API::Array*, API::String*, API::Data const*) + 100
2 WebKit 0x000000018a461648 WebKit::WebOpenPanelResultListenerProxy::chooseFiles(API::Array*, API::String*, API::Data const*) + 100
3 WebKit 0x000000018a413020 -[WKFileUploadPanel _chooseFiles:displayString:iconImage:] + 468
It seems to indicate an (overflow?) error in display the little thumbnail preview? Is there a way to prevent Safari from crashing when using file input, or at least don't render the thumbnail preview?
回答1:
Try this:
<input class="add__from-camera__input" type="file" accept="image/*;capture=camera">
来源:https://stackoverflow.com/questions/26955216/selecting-a-file-to-upload-causes-mobile-safari-to-crash