- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
首先,我对 WCF 服务和 dropzone JS 都不熟悉,但我正在尝试将两者结合起来创建一个简单的图像 uploader 。我的 WCF 可以正确处理我通过它上传到的元数据(所以我知道它正在正确地跨域传递内容),但是我从 Dropzone 捕获的流与我删除的图像不匹配.事实上,丢弃的每个图像都会在服务器端产生相同的编码字符串......
例如,我使用了这个 star image作为测试,并将图像上传到 base64 online converter ,我可以看到 base64 字符串的开头如下所示:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOYAAADbCAMAAABOUB36AAAAwFBMVEX...
但是,当我调试 WCF 代码时,base64 转换后的字符串如下所示:
LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5T1RUV0I1RFZZdTVlM2NTNQ0KQ29udG...
上面的字符串与为我尝试发送的每张图片创建的字符串相同。
现在所有适用的代码片段。我在一个项目中有一个简单的网页,在同一解决方案的另一个项目中有 WCF 相关文件。
索引.html:
<div class="col-lg-12">
<form action="http://localhost:39194/ImageRESTService.svc/AddImageStream/"
class="dropzone"
id="dropzone"></form>
</div>
...
Dropzone.options.dropzone = {
maxFilesize: 10, // MB
};
操作合约:
/* Stores a new image in the repository */
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "AddImageStream/")]
void AddImageStream(Stream img);
AddImageStream 实现:
public void AddImageStream(Stream img)
{
//try to save image to database
byte[] buffer = new byte[10000];
int bytesRead, totalBytesRead = 0;
string encodedData = "";
do
{
bytesRead = img.Read(buffer, 0, buffer.Length);
encodedData = encodedData + Convert.ToBase64String(buffer,
Base64FormattingOptions.InsertLineBreaks);
totalBytesRead += bytesRead;
} while (bytesRead > 0);
}
Webconfig适用件:
<services>
<service name="ImageRESTService.ImageRESTService" behaviorConfiguration="serviceBehavior">
<endpoint address="" behaviorConfiguration="web" contract="ImageRESTService.IImageRESTService" binding="webHttpBinding" bindingConfiguration="webHttpBinding"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxReceivedMessageSize="2147000000" />
</webHttpEndpoint>
</standardEndpoints>
<bindings>
<webHttpBinding>
<binding crossDomainScriptAccessEnabled="true" name="ImagesBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
<binding name="webHttpBinding" transferMode="Streamed" maxReceivedMessageSize="2147483647" maxBufferSize="10485760" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="1000000" />
</binding>
</webHttpBinding>
当我中断 encodedString 片段并且它与我的预期不匹配时,问题就很明显了。如果我将整个字符串复制到另一个从 base64 字符串生成图像的在线图像中,则它不是有效图像。在这一点上,我被卡住了,无法确定为什么我无法从 dropzone 中读取。
最佳答案
如果我解码你收到的 base64 字符串 LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5T1RUV0I1RFZZdTVlM2NTNQ0KQ29udG
我明白了
------WebKitFormBoundaryOTTWB5DVYu5e3cS5
续
所以我猜你在引用这篇文章中的元素时遇到了问题: Uploaded file only contains "WebKitFormBoundary"
关于javascript - Dropzone JS 上传到 WCF 获取错误数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38694753/
我正在使用 dropzone js,它在我需要 dropzone 的页面上运行得很好。在任何其他页面上,它都会给我一个“无效的 dropzone 元素” 错误消息并导致我的其他 javascript
我已经设置了带有可点击元素的 dropzone。单击该按钮会导致 dropzone 打开文件选择器两次,而不是一次,第二次会在选择第一个文件后立即打开。 初始化代码是: Dropzone.autoDi
我正在尝试使用Dropzone.js重新创建放置的文件/文件夹的文件夹结构。 有没有办法访问每个文件的完整路径,以便可以在php端重新创建目录结构? 最佳答案 这是一种简单的方法,您可以另外发送某些文
我有一个 DropZone除了一个异常(exception),表单工作得很好,我似乎无法根据需要精确地限制文件类型。 使用 acceptedFiles: "image/*"暗淡所有不是图像的文件夹和文
我正在尝试使用 dropzone.js FAQ 以编程方式将现有图像添加到我的 dropzone作为指南: // Add the existing image if it's there. // he
我正在使用 dropzone 来处理文件上传,并且我正在使用预览容器来指定应显示上传文件的位置。 所以我的配置如下(只剩下相关部分): var myDropzone = new Dropzone("#
我想限制 Dropzone 在您单击指定的 dropzone 区域时只选择一个文件,但我找不到任何参数来执行此操作。现在,当我选择一个文件并点击打开时,Dropzone 会立即再次弹出打开文件对话框而
我想上传一个文件并根据文件大小设置宽度和高度以适应给定的 div。例如: div size: width: 600px, height: 300px img size: width: 1200px,
我正在使用 Dropzone.autoDiscover = false 并使用 element.dropzone() 创建我的放置区。我想在另一个容器中显示处理后的文件,所以我使用了 previews
我想在我的 Web 应用程序中创建一个拖放区,用于上传图像并使用 ImageMagick 操作它们。我的拖放区始终自动上传所有图像,并在拖放区中的图像预览上显示“对象对象”错误。服务器上的上传工作正常
我已经在我的 ASP.MVC 4 上成功实现了 dropzone.js。 但我需要缩短下拉区域的高度并翻译文本。 有什么简单的方法可以做到吗?我试图修改 CSS 没有结果;下拉区域仍然采用相同的高度。
在 dropzone (或vue2dropzone),有没有办法禁用文件上传并且仅**允许通过拖放添加到dropzone。 我有一个设置,我使用自定义预览模板成功地在拖放区中设置了拖放到子区域(可单击
是否可以使用外部按钮通过 Dropzone 插件添加文件?我找到了 documentation但它没有回答我的问题。确实,我无法使用诸如单击之类的处理程序事件添加文件。有解决办法吗? 最佳答案 我猜您
当我使用 dropzone 上传多个文件时,图标显示在框外。我这张图,下图中的dropzone表格是黄色的,但是当我选择很多文件时,它们会溢出并显示在表格之外。我的 dropzone 的 CSS 是
最新的 dropzone.js 版本似乎不适用于 IE11。如何测试? 1) 打开 https://www.dropzonejs.com/examples/simple.html在 IE11 2) d
我正在尝试使用Dropzone.js在我的 Laravel 网站上。 这是我的设置: index.blade.php: @csrf 在我的 app.js 文件中,我有以下代码: window.
我正在为我的网站使用 dropzone.js 并尝试在上传之前重命名文件。最近 dropzone 添加了新函数 renameFile,我无法开始工作。这是错误还是我对功能的理解有误? console.
我正在制作一个比较应用,它有两个不同的拖放区域。每个都应该像一个单独的拖放区(用于替换或删除每个图像)。 问题: var previewaDropzone = new Dropzone("div#pr
我觉得我在这里失去了理智。我已经阅读了与我的问题相关的所有线程,我添加了“Dropzone.autoDiscover = false;”但似乎没有任何效果。 我不断得到: Uncaught Error
我在我的应用程序上使用 react-dropzone,并希望在一个页面上有多个 dropzones 来预览多个图像。例如,我希望能够将英雄图像拖放到在页面顶部显示英雄图像的拖放区。然后,我想将不同的图
我是一名优秀的程序员,十分优秀!