拥有带redux客户端和快递webapi的SPA.其中一个用例是将单个文件从浏览器上传到快速服务器.Express正在使用multer中间件解码文件上传并将其放入req对象的数组中.在localhost上运行时,一切都按预期工作.
但是,当应用程序部署到AWS时,它无法按预期运行.部署将express api推送到AWS Lambda函数,而redux客户端静态资产由Cloudfront CDN提供服务.在该环境中,上传的文件确实进入快速服务器,由multer处理,并且文件最终作为req.files数组中预期的第一个(也是唯一的)项.
问题是该文件包含错误的字节.例如,当我上传长度为2795字节的样本图像时,最终由multer解码的文件长度为4903字节.我尝试过的其他图像在multer解码并将它们放入req.files数组时,最终会变得大致相同.结果,文件已损坏,并且不显示为图像.
文件上传如下:
<input type="file" name="files" onChange={this.onUploadFileSelected} />
...
onUploadFileSelected = (e) => {
const file = e.target.files[0]
var formData = new FormData()
formData.append("files", file)
axios.post('to the url', formData, { withCredentials: true })
.then(handleSuccessResponse).catch(handleFailResponse)
}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用MemoryStorage和DiskStorage设置multer.两者都在localhost和aws lambda中工作,但两者都表现出相同的行为 - 文件大小更大并且在商店中已损坏.
我还尝试将multer设置为全局中间件(via app.use)和上传路由上的路由特定中间件(通过routes.post('the url', multerMiddlware, controller.uploadAction).再次,两者都表现出相同的行为.Multer中间件配置如下:
const multerMiddleware = multer({/* optionally set dest: '/tmp' */})
.array('files')
Run Code Online (Sandbox Code Playgroud)
一个区别是在localhost上,客户端和快递都通过http提供,而在aws中,客户端和快递都通过https提供.我不相信这会有所不同,但我还是无法测试 - 要么通过https运行localhost,要么通过http运行aws.
我注意到的另一个奇怪的事情是,当multer中间件存在时,其他中间件似乎没有按预期运行.相反next(),其他中间件将在控制器动作调用之前完全退出,而当控制器调用退出时,控制不会在next()调用后流回middlware,而不是将功能移动到控制器操作.删除multer中间件后,其他中间件会按预期运行.但是,这种观察是在localhost上进行的,整个端到端用例确实按预期运行.
什么可能会在部署到云时弄乱上传的图像文件有效负载,但在localhost上却没有?难道真的是https有所作为吗?
当我上传此文件(11228字节) …
在MVC3应用程序中,使用jquery不显眼的验证,以及带有[Remote]验证器的视图/模型:我正在尝试禁用提交按钮并在远程验证期间显示等待图标,并且当有效表单提交给服务器时.我以为我已经把它钉在了IE8上.
问题是,当表单无效时,GC和FF没有触发表单的提交事件,因此我在此事件期间禁用了提交按钮.但是,当表单无效时,IE8会触发此事件,导致用户永远无法再次单击它.(IE8不提交表单,但事件被解雇.)
我尝试将一个函数附加到提交按钮的单击事件.在那里,我禁用了提交按钮,显示了等待图标,并且有:
$('[data-app-form-submit-button="true"]').live('click', function (e) {
var form = $(this).parents('form');
var icon = form.find('[data-app-form-submitting-icon="true"]');
icon.show();
$(this).attr('disabled', 'disabled');
$.ajaxSetup({ async: false });
var isValid = form.valid();
$.ajaxSetup({ async: true });
alert(isValid);
});
Run Code Online (Sandbox Code Playgroud)
问题是,ajax设置调用并没有真正关闭异步.如果我将它移出click函数,但它会禁用所有内容的异步.相反,页面立即警告"true",通过在远程验证操作方法上设置断点进行测试.
有任何想法吗?
附加说明:
我忘了提一下,在IE8中,当有问题的文本框未能在客户端上进行验证时,才会触发提交事件.例如,如果它不需要或正则表达式,则触发submit().对于远程验证操作方法,不会触发它.但是,一旦客户端验证失败,后续远程验证也会触发IE8提交事件.
对Russ Cam的回应(评论#1)
以下是viewmodel中的相关代码:
public class SignUpForm : IValidatableObject
{
[DataType(DataType.EmailAddress)]
[Display(Name = "Email Address")]
[Required(ErrorMessage = "Email Address is required.")]
[RegularExpression(@"^(email regex here)$",
ErrorMessage = "This is not a valid email address.")]
[Remote("Validate", "ControllerName", "AreaName", HttpMethod = "POST")]
public string EmailAddress { get; set; …Run Code Online (Sandbox Code Playgroud) jquery jquery-validate unobtrusive-validation asp.net-mvc-3 remote-validation
我可以AbstractValidators使用a 注册FluentValidation FluentValidatorFactory.但是,它感觉不对,因为并非所有IoC容器注册都在bootstrap/composition root期间发生.相反,流利的验证器由一个单独的工厂注册:
所述组合物根:
public class SimpleDependencyInjector : IServiceProvider
{
public readonly Container Container;
public SimpleDependencyInjector()
{
Container = Bootstrap();
}
internal Container Bootstrap()
{
var container = new Container();
container.Register< // ...register all non-fluent-validator types, then
container.Verify();
return container;
}
public object GetService(Type serviceType)
{
return ((IServiceProvider)Container).GetService(serviceType);
}
}
Run Code Online (Sandbox Code Playgroud)
一个抽象的流利验证工厂,仅依赖于IServiceProvider
public abstract class FluentValidatorFactory : ValidatorFactoryBase
{
private IServiceProvider Injector { get; set; }
protected FluentValidatorFactory(IServiceProvider injector) …Run Code Online (Sandbox Code Playgroud) dependency-injection fluentvalidation fluentvalidation-2.0 open-generics simple-injector
我有一个表单+布局,如下所示:
<form ...>
<div id="editor">
[form html]
<input type="submit" value="Submit form" />
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
以下javascript:
$(function() {
var form = $('#editor').parents('form');
alert(form.length); // this alerts "1"
$(document).on('submit', 'form', function() {
alert('document form submit fired'); // this works as expected (alerts)
});
form.on('submit', function() {
alert('selected form submit fired'); // this is never alerted
});
});
Run Code Online (Sandbox Code Playgroud)
此表单不是通过ajax加载的.页面加载时,第一个对话框警告"1".但是,在提交表单时,只会触发一个警报 - 触发提交文档中所有表单的警报.
为什么会这样?
我一直在尝试将LINQ表达式重构为一个方法,并且已经遇到了" Internal .NET Framework Data Provider error 1025."和" The parameter 'xyz' was not bound in the specified LINQ to Entities query expression."异常.
以下是实体模型的相关部分(使用EF 4.2/LINQ to Entities):
public class Place : Entity
{
public string OfficialName { get; protected internal set; }
public virtual ICollection<PlaceName> { get; protected internal set; }
}
public class PlaceName : Entity
{
public string Text { get; protected internal set; }
public string AsciiEquivalent { get; protected internal set; }
public virtual Language …Run Code Online (Sandbox Code Playgroud) linq-to-entities expression-trees predicatebuilder entity-framework-4 linqkit
我有一个MVC应用程序,它部署到运行在Windows Server 2012虚拟机上的Windows Azure托管服务.在web.config文件中,我有3个部分加密的使用PKCS12ProtectedConfigurationProvider:connectionStrings,dataCacheClients,和system.net/mailSettings/smtp.以下是相关部分的外观:
<configuration>
...
<configProtectedData>
<providers>
<add name="CustomProvider" thumbprint="[this is secret]"
type="Pkcs12ProtectedConfigurationProvider.Pkcs12ProtectedConfigurationProvider, PKCS12ProtectedConfigurationProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=34da007ac91f901d" />
</providers>
</configProtectedData>
...
<connectionStrings configProtectionProvider="CustomProvider">
<EncryptedData ... ommitted for brevity
</connectionStrings>
...
<system.net>
<mailSettings>
<smtp configProtectionProvider="CustomProvider">
<EncryptedData ommitted for brevity
</smtp>
</mailSettings>
</system.net>
...
<dataCacheClients configProtectionProvider="CustomProvider">
<EncryptedData ommitted for brevity
</dataCacheClients>
...
</configuration>
Run Code Online (Sandbox Code Playgroud)
所有上述工作都完美无缺.部署到Azure时,连接字符串,SMTP邮件和数据缓存都可以正常工作.该PKCS12ProtectedConfiguration供应商使用我的自定义证书解密的部分,一切都很好.
但是我似乎无法使用相同的方法进行加密web.config/appSettings.当我尝试将以下内容部署到Azure时...
<configuration>
...
<appSettings configProtectionProvider="CustomProvider">
<EncryptedData ommitted for brevity
</appSettings>
... …Run Code Online (Sandbox Code Playgroud) 我正在尝试调整大小然后正方形裁剪传入的图像.我有我的图像,ReadOnlyStream并希望输出到MemoryStream.
我正在使用ImageResizer库来做到这一点.
我希望我的图像首先缩小尺寸,然后将中心方形裁剪成它们.我正在使用此代码,但它不会产生我需要的代码.它什么都没产生......
var resultStream = new MemoryStream();
ImageJob job = new ImageJob(imageStream, resultStream, new Instructions {
Width = 100,
Height = 100,
Mode = FitMode.Crop
});
job.Build();
Run Code Online (Sandbox Code Playgroud)
此代码应对大图像进行下采样,并根据库默认值(中心裁剪)裁剪它们.
我没有在web.config中提供任何特定的配置,因为我理解它并不是必需的.
我究竟做错了什么?
使用typescript 1.4我在以下代码行中遇到了有趣的错误:
var dateFrom:Date;
var dateTo:Date;
if(typeof discount.dateFrom === "string"){
dateFrom = new Date(discount.dateFrom); // Line 362
} else {
dateFrom = discount.dateFrom;
}
if(typeof discount.dateTo === "string"){
dateTo = new Date(<string>discount.dateTo); // Line 368
} else {
dateTo = discount.dateTo;
}
Run Code Online (Sandbox Code Playgroud)
转换器返回以下内容:
[FULL_PATH]/Quotation.ts(362,37): error TS2345: Argument of type 'Date' is not assignable to parameter of type 'string'.
[FULL_PATH]/Quotation.ts(368,35): error TS2352: Neither type 'Date' nor type 'string' is assignable to the other.
Run Code Online (Sandbox Code Playgroud)
与线362和368的区别在于我试图解决问题的两种情况.
我在代码中的其他地方使用了这个gimmic,它运行正常.
我在lib.d.ts中包含了Date构造函数的定义以供参考:
new (): Date;
new (value: …Run Code Online (Sandbox Code Playgroud) 今天检查AppHarbor.我的主要问题是标题,但我还有其他与git + windows相关的问题.
首先,与此视频相关.我喜欢我可以为部署指定配置转换的想法.我的问题是,它必须是Web.Release.config转换吗?我实际上想通过将其用作集成测试的qa部署来测试它.我可以将变换指定为Web.DeployToAppHarbor.config吗?
其次,我已经读过有关crlf问题的内容.当我跑步时git add .,我应该得到所有这些消息吗?
warning: CRLF will be replaced by LF in [path].
The file will have its original line endings in your working directory.
Run Code Online (Sandbox Code Playgroud)
沿着这些方向,我还应该在跑完之后得到所有这些信息git commit -m "Initial commit"吗?
create mode 100644 [path]
Run Code Online (Sandbox Code Playgroud)
如果这些都是正常的,有没有办法让git bash不那么冗长?
假设我有一组3个单选按钮:
<div>
<label>
<input type="radio" name="Who" value="Myself"
checked="@isMyselfChecked" data-bind="checked: who" />
Mine
</label>
<label>
<input type="radio" name="Who" value="MemberId"
checked="@isMemberIdChecked" data-bind="checked: who" />
I know the member's ID
</label>
<label>
<input type="radio" name="Who" value="MemberUrl"
checked="@isMemberUrlChecked" data-bind="checked: who" />
I know the member's URL
</label>
</div>
Run Code Online (Sandbox Code Playgroud)
当用户选择第一个单选按钮(Mine/Myself)时,不需要额外的输入.但是,在选择第二或第三时,额外的输入是必需的:
<div>
<input type="text" name="MemberId" placeholder="Enter Member ID"
data-bind="toggleWho: who()" style="display: none" />
<input type="text" name="MemberUrl" placeholder="Enter Member URL"
data-bind="toggleWho: who()" style="display: none; width: 450px;" />
</div>
Run Code Online (Sandbox Code Playgroud)
只需拥有data-bind="visible: who() === '[MemberId|MemberUrl]'"依赖文本框就足够了.但是,如果我想添加淡入/淡出过渡怎么办?
我尝试了 …
jquery ×3
animation ×1
appharbor ×1
appsettings ×1
asp.net-mvc ×1
aws-lambda ×1
axios ×1
azure ×1
c# ×1
deployment ×1
encryption ×1
express ×1
file-upload ×1
form-submit ×1
git ×1
imageresizer ×1
knockout-2.0 ×1
knockout.js ×1
linqkit ×1
multer ×1
resize-crop ×1
typescript ×1
web-config ×1