当使用下划线模板时,我想在anchor的href属性中插入一个值,如
a(href= "<%= id %>", class='products') //underscore template in jade
Run Code Online (Sandbox Code Playgroud)
但是输出是
<a href="<% id %>" class="products">
Run Code Online (Sandbox Code Playgroud)
那么如何转义<和>符号,并正确插值?
我尝试用fluent-ffmpeg创建一个视频缩略图,这是我的代码
var ffmpeg = require('fluent-ffmpeg');
exports.thumbnail = function(){
var proc = new ffmpeg({ source: 'Video/express2.mp4',nolog: true })
.withSize('150x100')
.takeScreenshots({ count: 1, timemarks: [ '00:00:02.000' ] }, 'Video/', function(err, filenames) {
console.log(filenames);
console.log('screenshots were saved');
});
}
Run Code Online (Sandbox Code Playgroud)
但我一直收到这个错误
"mate data contains no duration, aborting screenshot creation"
Run Code Online (Sandbox Code Playgroud)
任何想法为什么,
顺便说一句,在Windows上,我将ffmpeg文件夹放在c/ffmpeg中,我将ffmpeg/bin添加到我的环境varable中,我不知道fluent-ffmpeg是否需要知道ffmpeg的路径,但我可以成功使用下面的代码创建缩略图
exec("C:/ffmpeg/bin/ffmpeg -i Video/" + Name + " -ss 00:01:00.00 -r 1 -an -vframes 1 -s 300x200 -f mjpeg Video/" + Name + ".jpg")
Run Code Online (Sandbox Code Playgroud)
请帮我!!!
我得到这个错误说
error:request entity too large
Run Code Online (Sandbox Code Playgroud)
上传大约30MB的视频时,
这是设置代码
app.use(express.bodyParser({
uploadDir:'./Temp',
maxFieldsSize:'2 * 1024 * 1024 * 1024 ',
}));
Run Code Online (Sandbox Code Playgroud)
我不确定如何设置maxFieldsSize属性,需要一些帮助!
我使用 connect-busboy 来处理文件上传,这是代码
req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
var type = mimetype.split('/')[1]
var newName = (new Date()).valueOf();
var saveTo = path.join(__dirname, '../../userUpload',req.user._id+'', newName+'.'+type);
file.pipe(fs.createWriteStream(saveTo,{flags: 'w'}));
});
Run Code Online (Sandbox Code Playgroud)
如您所见,我尝试将上传的文件保存在动态目录(以 user._id 命名)中,并使用新的文件名;
但它给了我一个错误说
"Error: ENOENT, open '\userUpload\53a65fde4e22939811aa306d\1404636837084.mp4' "
Run Code Online (Sandbox Code Playgroud)
但是当我首先手动创建 user._id 目录时,它会起作用,所以 fs.createWriteStream 无法处理动态目录,对吗?
我怎样才能做到这一点?
我正在按照本教程使用s3和lambda实现生成缩略图.我坚持将不存在的请求重定向到lambda
我的s3存储桶是私有的,我使用带有Cognito idtoken的预签名网址来访问其内容,它可以工作.
现在,如果我向尚未生成的缩略图发出请求(s3中不存在),我希望s3将请求重定向到lambda.我无法弄清楚如何做到这一点.
这是s3路由角色
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals/>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<Protocol>https</Protocol>
<HostName>MY_LAMBDA_DOMAIN</HostName>
<ReplaceKeyPrefixWith>dev/photos?key=</ReplaceKeyPrefixWith>
<HttpRedirectCode>307</HttpRedirectCode>
</Redirect>
Run Code Online (Sandbox Code Playgroud)
当我使用预先签名的URL访问不存在的缩略图时,它给出了403错误,因此我尝试使用s3端点预先签名该URL
const s3 = new AWS.S3({endpoint: 'http://s3-website.us-east-2.amazonaws.com'})
s3.getSignedUrl('getObject', {
Bucket: BUCKET,
Key: 'userId/test-thumb.jpg',
Expires: signedUrlExpireSeconds
})
Run Code Online (Sandbox Code Playgroud)
我注意到在上面提到的教程中,它使用了公共s3存储桶.我不确定是否可以在私有桶中实现此解决方案.
它与s3政策有什么关系吗?目前我的私人存储桶没有附加任何政策
任何建议将不胜感激,谢谢
我知道骨干文档说 fetch不应该用于在页面加载时填充集合,我有点弄清楚原因:
var appCollection = Backbone.Collection.extend({
model:appModel,
url:'api/app',
initialize:function(){
this.fetch();
},
});
var homeView = Backbone.View.extend({
el:'#content',
initialize:function(){
this.collection = new appCollection(appModel)
this.render()
},
render: function () {
var that = this;
alert(1);
_.each(this.collection.models, function (item) {
that.renderApp(item);
}, this);
},
renderApp: function (item) {
var appview = new appView({
model: item
});
this.$el.append(appview.render().el);
}
})
var home = new homeView();
Run Code Online (Sandbox Code Playgroud)
homeview.render函数实际上是在获取集合之前调用的,所以当我删除alert(1); 我的应用程序不会被渲染,我得到一些错误说"appname"(模板)是未定义的.
知道如何做到这一点?
fetch方法非常方便,我不介意等待几秒钟,实际上我打算显示一个进度条,表明页面正在初始化,因为我有很多其他东西要下载,所以可以使用fetch和当实际获取集合时,然后代码继续运行???
根据表单向导文档,初始数据应该是静态字典.但是有可能动态地提供初始数据.
这是我的情况
def get_context_data(self, form, **kwargs):
context = super(debugRegistrationWizard, self).get_context_data(form=form, **kwargs)
email = InvitationKey.objects.get_key_email(self.kwargs['invitation_key'])
context.update({'invitation_key': self.kwargs['invitation_key']})
return context
Run Code Online (Sandbox Code Playgroud)
电子邮件是我想要的步骤0中的初始数据,但我只能在get_context_data方法中获取此电子邮件.我怎样才能做到这一点?
顺便说一句,如果formwizard.as_view的urlconf接受如下参数:
url(r'^registration/(?P<invitation_key>\w+)$', debugRegistrationWizard.as_view(FORMS)),
Run Code Online (Sandbox Code Playgroud)
剂量它意味着我必须将变量传递给我的表单的动作属性,因为否则当我提交表单时,我将得到一个未找到的url错误.
我正在构建一个博客系统,允许用户将图像添加到他们的博客中.
当用户添加图片时,图片会自动上传,这发生在博客发布之前,那么我应该如何处理上传的图片,这些图片有点像临时图片,因为如果用户发布博客,这些图片会有此博客的外键,并保存到某个文件夹中,但如果用户丢弃该博客,则应删除这些临时图像.
问题是如何在博客实际发布时获得首次上传的图片?我应该在哪里存储这些临时图像?如何判断用户是否放弃了博客?
问题是我渲染视图并发送一些数据
console.log(products); // shows an array
res.render('seller/sell',{'shop_id':req.user.shop_id ,'products':products});
Run Code Online (Sandbox Code Playgroud)
我在玉器中保存这样的数据
input(id='shop_id',type='hidden',name='shop_id',value='#{shop_id}')
input(id='pd',type='hidden',name='pd',value='#{products}')
if(products !='')
each val , key in products
a(href!='home/sell/edit?id=#{val.id} ',class='product')
img(class='product_thum',src!='#{ val.product_thum}',alt!='#{ val.product_name}',title!='#{ val.product_name}')
p.product_name #{ val.product_name}
Run Code Online (Sandbox Code Playgroud)
然后我尝试获得产品
var d = $('#pd').val();
console.log(typeof d); //shows string
Run Code Online (Sandbox Code Playgroud)
我知道产品shuld是一个阵列否则
if(products !='')
each val , key in products
a(href!='home/sell/edit?id=#{val.id} ',class='product')
img(class='product_thum',src!='#{ val.product_thum}',alt!='#{ val.product_name}',title!='#{ val.product_name}')
p.product_name #{ val.product_name}
Run Code Online (Sandbox Code Playgroud)
不工作,但为什么我需要数组时得到一个字符串?
我做错了什么?
当加载骨干应用程序时(对于我的应用程序,这意味着加载了页面),我需要初始收集数据,骨干文档说:
<script>
var accounts = new Backbone.Collection;
accounts.reset(<%= @accounts.to_json %>);
var projects = new Backbone.Collection;
projects.reset(<%= @projects.to_json(:collaborators => true) %>);
</script>
Run Code Online (Sandbox Code Playgroud)
我不明白这一点.这意味着我应该使用初始数据来渲染页面
{{collection_initial_data}}
Run Code Online (Sandbox Code Playgroud)
我在后端使用django,所以如何将上面的代码翻译成django模板,比如
<script>
var accounts = new Backbone.Collection;
accounts.reset({{ @accounts.to_json }});
var projects = new Backbone.Collection;
projects.reset({{ @projects.to_json(:collaborators => true) }});
</script>
Run Code Online (Sandbox Code Playgroud)
无论如何,我对获取骨干采集的初始数据感到困惑.
node.js ×5
django ×3
backbone.js ×2
express ×2
javascript ×2
pug ×2
thumbnails ×2
upload ×2
amazon-s3 ×1
aws-lambda ×1
collections ×1
dir ×1
escaping ×1
fetch ×1
ffmpeg ×1
html ×1
multipart ×1
post ×1
python ×1
render ×1
templates ×1
urlconf ×1