Devise is not working with flash runtime of Plupload - ruby-on-rails-3

I'm running Rails 3.0.9, Devise 1.4 and Plupload 1.4.3.2. Everything works fine with HTML5 runtime.
But when I add before_filter authenticate_user! to my application controller and switch to flash runtime things go bad.
When I try to upload some images:
Started POST "/uploads" for 127.0.0.1 at 2011-06-29 12:58:48 +0200
Processing by UploadsController#create as JS
Parameters: {"Filename"=>"me_dark_ui_01.png", "name"=>"me_dark_ui_01.png", "_inzercia_session"=>"BAh7CEkiEF9jc3JmX3Rva2VuBjoGRUZJIjE0NjlmSkZCd25VMkl1UEFzTTFUVTUwTFVYTjRHYkJJSTlGKzBWTXFlSzc0PQY7AEZJIhl3YXJkZW4udXNlci51c2VyLmtleQY7AFRbCEkiCVVzZXIGOwBGWwZpB0kiIiQyYSQxMCQ4SkVLZGVja0dLVk5jbm10MEVoNmRPBjsAVEkiD3Nlc3Npb25faWQGOwBGIiUwY2Y1ZjM4MDRlMGEzOTM3MzQ5ZTQzM2RkNjk5MTc0Mg%253D%253D--b0e6653c44645e7db420dff1dd9908f4b8938e6d", "authenticity_token"=>"469fJFBwnU2IuPAsM1TU50LUXN4GbBII9F+0VMqeK74=", "upload_token"=>"07ea1a1ec4539436878b8e13ae6347164fcd3eac", "_http_accept"=>"application/javascript", "file"=>#<ActionDispatch::Http::UploadedFile:0x520bae0 #original_filename="me_dark_ui_01.png", #content_type="application/octet-stream", #headers="Content-Disposition: form-data; name=\"file\"; filename=\"me_dark_ui_01.png\"\r\nContent-Type: application/octet-stream\r\n", #tempfile=#<File:C:/Users/Deli/AppData/Local/Temp/RackMultipart20110629-4684-osz0l9>>, "Upload"=>"Submit Query"}
Completed in 21ms
My Uploads#create action
def create
#upload = Upload.new
#upload.photo = params[:file] if params.has_key?(:file)
# detect Mime-Type (mime-type detection doesn't work in flash)
#upload.photo_content_type = MIME::Types.type_for(params[:name]).to_s if params.has_key?(:name)
#upload.upload_token = params[:upload_token]
#upload.save!
strong textrespond_to :js
end
Plupload settings:
<% session_key_name = Rails.application.config.session_options[:key] %>
jQuery(document).ready(function() {
$("#uploader").pluploadQueue({
runtimes: 'flash',
url: '<%= uploads_path %>',
max_file_size: '10mb',
multiple_queues: true,
flash_swf_url: "/javascripts/plupload/plupload.flash.swf",
silverlight_xap_url: "/javascripts/plupload/plupload.silverlight.xap",
multipart: true,
multipart_params: {
'_http_accept': 'application/javascript',
'authenticity_token' : '<%= form_authenticity_token %>',
'upload_token' : '<%= #upload_token %>',
'<%= session_key_name %>' : encodeURIComponent('<%= u cookies[session_key_name] %>')
},
filters: [
{title: "Images", extensions: "jpg,jpeg,png"}
],
init: {
FileUploaded: function(up, file, info) {
eval(info["response"]);
}
}
});
});

Problem solved with adding
urlstream_upload: true
to the plupload configuration.

Related

How to add HTML comments to index.html when doing a build in Vue CLI?

Update 1: Fixed syntax issue that caused my initial build errors.
Update 2: Found my own solution using a Webpack plugin. See the accepted solution.
I want to add some custom HTML comments in the public/index.html during a build. I added something like this:
<!--
My Application
Version: <%= VUE_APP_VERSION %>
Build date: <%= VUE_APP_BUILD_DATE %>
-->
In my vue.config.js, I've set VUE_APP_VERSION and VUE_APP_BUILD_DATE accordingly:
let today = new Date().toLocaleDateString(undefined, {
year: 'numeric',
month: '2-digit',
day: '2-digit'
})
process.env.VUE_APP_VERSION = require('./package.json').version
process.env.VUE_APP_BUILD_DATE = today
But when I actually build (npm run build), the comments are removed completely and everything is minimized.
How do I preserve my comments?
Found a solution using HtmlWebpackPlugin and WebpackAutoInject plugins in my vue.config.js file; ditching the VUE_APP_* variable use in my index.html as it was causing me build errors.
npm install html-webpack-plugin --save-dev
npm install webpack-auto-inject-version --save-dev
My new vue.config.js:
const HtmlWebpackPlugin = require('html-webpack-plugin')
const WebpackAutoInject = require('webpack-auto-inject-version')
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? process.env.VUE_APP_PUBLIC_PATH_EN
: '/',
configureWebpack: {
plugins: [
// index.html customization
new HtmlWebpackPlugin({
template: 'public/index.html',
filename: 'index.html',
inject: true,
deploy: process.env.VUE_APP_DEPLOY,
webtrends: '/webtrends/scripts/webtrends.load.js', // include webtrends script for OPS only
minify: {
removeComments: false
}
}),
// Auto inject version
new WebpackAutoInject({
SILENT: true,
// options
components: {
AutoIncreaseVersion: false,
InjectAsComment: false
},
componentsOptions: {
InjectByTag: {
// https://www.npmjs.com/package/dateformat
dateFormat: 'isoUtcDateTime'
}
}
})
]
}
}
Then in my index.html (with a custom script to include on build):
<!--
My application
Version: [AIV]{version}[/AIV]
Build date: [AIV]{date}[/AIV]
-->
<% if (htmlWebpackPlugin.options.deploy === 'ops') { %>
<script src="<%= htmlWebpackPlugin.options.webtrends %>"></script>
<% } %>
I was able to get this to work by using "HTML-escaped interpolation" syntax.
<%= VALUE %> for unescaped interpolation;
<%- VALUE %> for HTML-escaped interpolation; 👈🏻 this one
<% expression %> for JavaScript control flows.
Note the different closing tag too.
So your index.html becomes:
<!--
My Application
Version: <%- VUE_APP_VERSION %>
Build date: <%- VUE_APP_BUILD_DATE %>
-->

Rollupjs: Ignore lines of code

One of my javascript files is using the lodash template syntax:
const deliveryClient = new DeliveryClient({
enablePreviewMode: <%= options.enablePreviewMode %>,
projectId: '<%= options.projectId %>',
previewApiKey: '<%= options.previewApiKey %>',
defaultLanguage: '<%= options.defaultLanguage %>',
enableAdvancedLogging: <%= options.enableAdvancedLogging %>,
baseUrl: '<%= options.baseUrl %>',
typeResolvers: typeResolvers
});
But when i run rollup -c i'm getting a "unexpected token" error. Is there a way to tell rollup to ignore (just put it in the output file) some lines of code?
Or is there an other/better way to deal with lodash template syntax within RollupJS?
I just want to above code snippet to be in my final output!
I fixed it by using the rollup-plugin-replace plugin.
In my javascript I changed my code into the following:
const deliveryClient = new DeliveryClient('KENTICOOPTIONS');
and in the rollup.config.js I added the plugin with the following configuration:
replace({
include: 'lib/templates/plugin.template.js',
KENTICOOPTIONS: '<%= serialize(options) %>'
})
So this gives the final output of:
const deliveryClient = new DeliveryClient('<%= serialize(options) %>');
Which is exactly what i needed!

AWS Api Gateway proxy resource using Cloudformation?

I'm trying to proxy an S3 bucket configured as a website from an API Gateway endpoint. I configured an endpoint successfully using the console, but I am unable to recreate the configuration using Cloudformation.
After lots of trial and error and guessing, I've come up with the following CF stack template that gets me pretty close:
Resources:
Api:
Type: 'AWS::ApiGateway::RestApi'
Properties:
Name: ApiDocs
Resource:
Type: 'AWS::ApiGateway::Resource'
Properties:
ParentId: !GetAtt Api.RootResourceId
RestApiId: !Ref Api
PathPart: '{proxy+}'
RootMethod:
Type: 'AWS::ApiGateway::Method'
Properties:
HttpMethod: ANY
ResourceId: !GetAtt Api.RootResourceId
RestApiId: !Ref Api
AuthorizationType: NONE
Integration:
IntegrationHttpMethod: ANY
Type: HTTP_PROXY
Uri: 'http://my-bucket.s3-website-${AWS::Region}.amazonaws.com/'
PassthroughBehavior: WHEN_NO_MATCH
IntegrationResponses:
- StatusCode: 200
ProxyMethod:
Type: 'AWS::ApiGateway::Method'
Properties:
HttpMethod: ANY
ResourceId: !Ref Resource
RestApiId: !Ref Api
AuthorizationType: NONE
RequestParameters:
method.request.path.proxy: true
Integration:
CacheKeyParameters:
- 'method.request.path.proxy'
RequestParameters:
integration.request.path.proxy: 'method.request.path.proxy'
IntegrationHttpMethod: ANY
Type: HTTP_PROXY
Uri: 'http://my-bucket.s3-website-${AWS::Region}.amazonaws.com/{proxy}'
PassthroughBehavior: WHEN_NO_MATCH
IntegrationResponses:
- StatusCode: 200
Deployment:
DependsOn:
- RootMethod
- ProxyMethod
Type: 'AWS::ApiGateway::Deployment'
Properties:
RestApiId: !Ref Api
StageName: dev
Using this template I can successfully get the root of the bucket website, but the proxy resource gives me a 500:
curl -i https://abcdef.execute-api.eu-west-1.amazonaws.com/dev/index.html
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
Content-Length: 36
Connection: keep-alive
Date: Mon, 11 Dec 2017 16:36:02 GMT
x-amzn-RequestId: 6014a809-de91-11e7-95e4-dda6e24d156a
X-Cache: Error from cloudfront
Via: 1.1 8f6f9aba914cc74bcbbf3c57e10df26a.cloudfront.net (CloudFront)
X-Amz-Cf-Id: TlOCX3eemHfY0aiVk9MLCp4qFzUEn5I0QUTIPkh14o6-nh7YAfUn5Q==
{"message": "Internal server error"}
I have no idea how to debug that 500.
To track down what may be wrong, I've compared the output of aws apigateway get-resource on the resource I created manually in the console (which is working) with the one Cloudformation made (which isn't). The resources look exactly alike. The output of get-method however, is subtly different, and I'm not sure it's possible to make them exactly the same using Cloudformation.
Working method configuration:
{
"apiKeyRequired": false,
"httpMethod": "ANY",
"methodIntegration": {
"integrationResponses": {
"200": {
"responseTemplates": {
"application/json": null
},
"statusCode": "200"
}
},
"passthroughBehavior": "WHEN_NO_MATCH",
"cacheKeyParameters": [
"method.request.path.proxy"
],
"requestParameters": {
"integration.request.path.proxy": "method.request.path.proxy"
},
"uri": "http://muybucket.s3-website-eu-west-1.amazonaws.com/{proxy}",
"httpMethod": "ANY",
"cacheNamespace": "abcdefg",
"type": "HTTP_PROXY"
},
"requestParameters": {
"method.request.path.proxy": true
},
"authorizationType": "NONE"
}
Configuration that doesn't work:
{
"apiKeyRequired": false,
"httpMethod": "ANY",
"methodIntegration": {
"integrationResponses": {
"200": {
"responseParameters": {},
"responseTemplates": {},
"statusCode": "200"
}
},
"passthroughBehavior": "WHEN_NO_MATCH",
"cacheKeyParameters": [
"method.request.path.proxy"
],
"requestParameters": {
"integration.request.path.proxy": "method.request.path.proxy"
},
"uri": "http://mybucket.s3-website-eu-west-1.amazonaws.com/{proxy}",
"httpMethod": "ANY",
"requestTemplates": {},
"cacheNamespace": "abcdef",
"type": "HTTP_PROXY"
},
"requestParameters": {
"method.request.path.proxy": true
},
"requestModels": {},
"authorizationType": "NONE"
}
The differences:
The working configuration has responseTemplates set to "application/json": null. As far as I can tell, there's no way to set a mapping explicitly to null using Cloudformation. My CF method instead just has an empty object here.
My CF method has "responseParameters": {},, while the working configuration does not have responseParameters at all
My CF method has "requestModels": {},, while the working configuration does not have requestModels at all
Comparing the two in the console, they are seemingly exactly the same.
I'm at my wits end here: what am I doing wrong? Is this possible to achieve using Cloudformation?
Answer: The above is correct. I had arrived at this solution through a series of steps, and re-applied the template over and over. Deleting the stack and deploying it anew with this configuration had the desired effect.

Spree 3.0.0 use S3 - image links are incorrect for both admin and front side pages

I have recently downloaded Spree 3.0.8 running on Amazon CLI Elastic Beanstalk.
I have encountered a problem that I can't work it out for 2 weeks.
My Spree commerce is able to upload the product image to S3 bucket using the following:
attachment_config = {
s3_credentials: {
access_key_id: "XXXXXXXXXXX",
secret_access_key: "gO7XXXXXXXXXX",
bucket: "sirac-products"
},
storage: :s3,
s3_headers: { "Cache-Control" => "max-age=31557600" },
s3_protocol: "https",
bucket: "sirac-products",
url: "s3-website-ap-southeast-2.amazonaws.com",
styles: {
mini: "48x48>",
small: "100x100>",
product: "240x240>",
large: "600x600>"
},
path: "/:class/:id/:style/:basename.:extension",
default_url: "/:class/:id/:style/:basename.:extension",
default_style: "product"
}
attachment_config.each do |key, value|
Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
end
The problem is the image links aren't correct both on admin and front side.
( The image link uses s3.amazonaws.com instead s3-ap-southeast-2.amazonaws.com).
Would anyone help me to issue this issue?
In your spree config file, try copying this code and modify according to you (ex: bucket name, key id and all... ) see if this works, and please make sure the region you are entering is correct. You can check that in s3 bucket as well
config/initializers/spree.rb
#--------------------------------------------
Spree.config do |config|
config.admin_interface_logo = "logo.png" #don copy this
attachment_config={
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['S3_BUCKET_NAME']
},
storage: :s3,
s3_headers: {"Cache-Control"=>"max-age=31557600"},
s3_protocol: "https",
bucket: ENV['ENV_BUCKET_NAME'],
s3_host_name: "s3-us-west-2.amazonaws.com", #your region
url: "url",
styles: {
mini: "60x76#",
small: "270x340#", #totally depends how you are going to keep the styles
product:"670x844#",
large: "700x881>"
},
path: "/spree/:class/:id/:style/:basename.:extension",
default_url: "/spree/products/:id/:style/:basename.:extension",
default_style: "product",
}
attachment_config.each do |key,value|
Spree::Image.attachment_definitions[:attachment][key.to_sym]=value
end
end
This worked for me, hope will do the same for you

Sencha Touch 2.0 Manifest Query String

I'm setting my app up to run offline and I have hit a brick wall. All of my files are being cached but I noticed in the Safari console that the app is adding a query sting to the filename so the correct file is not loaded. In Safari the link looks like this
http://serverpath/resources/data/data.json?_dc=1337372230084&node=root&page=1&start=0&limit=25
Is there any way to prevent the query string from being added? My data store code is below.
Ext.define('App.store.Sections', {
extend: 'Ext.data.TreeStore',
requires: [
'App.model.Sections'
],
config: {
autoLoad: true,
model: 'App.model.Sections',
proxy: {
type: 'ajax',
url: 'resources/data/data.json',
reader: {
type: 'json',
rootProperty: 'items'
}
}
}
});
See Ext.Ajax.setDisableCaching.
Be careful of the double negation: it has to be set to false in your case : you don't want to use the disable caching system.