因此,当通过ajax上传图像时,我遇到这样的事情:
$("input#uploadedfile").on("change", function(){
var file = this.files[0],
});
Run Code Online (Sandbox Code Playgroud)
假设#uploadedfile是一个file类型输入,this.files[0]只是针对上传的第一个文件?这个jQuery也做同样的事情吗?:
var file = $(this).get(0).files[0]
Run Code Online (Sandbox Code Playgroud) 这是我的存储桶政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Allow All",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::my-bucket/*"
},
{
"Sid": "Deny All Actions On All But Media and Static Unless Defined User",
"Effect": "Deny",
"NotPrincipal": {
"AWS": "arn:aws:iam::**********:root"
},
"Action": "s3:*",
"NotResource": [
"arn:aws:s3:::my-bucket/media/*",
"arn:aws:s3:::my-bucket/static/*"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
所以基本上我有3个文件夹:backup,static和media.我的媒体和静态文件夹中的所有对象都是公共的.
但是,当我单击完整路径时,例如此对象:( https://s3.us-east-2.amazonaws.com/my-bucket/media/x12wHSRoM9szjvY此obj实际上不存在但路径格式相同)即使它是图像,也没有.jpg或.png扩展名.这可能是我的问题的原因,如果是这样,我怎么能解决这个问题,以便我可以访问原始对象而不是在点击它时下载它?
Kotlin的主要功能:
fun main(args : Array<String>) {
println("Hello, world!")
}
Run Code Online (Sandbox Code Playgroud)
为什么要传入数组?
import java.util.*
Run Code Online (Sandbox Code Playgroud)
我正在尝试从我的数组中生成一个随机字符串:
val days = arrayOf("Tuesday", "Thursday", "Saturday")
val chosenDay = days[Random().nextInt(2)]
Run Code Online (Sandbox Code Playgroud)
然而,days[Random().nextInt(2)]似乎只在周二和周四返回.我无法在任何地方找到答案,但为什么nextInt()不使用从零开始的编号?
我把它改成了days[Random().nextInt(3)],现在它工作正常.
我的代码:
class Team (val name: String, val aggressive: Boolean = true) {
val attendance: Int
init {
if (aggressive){
attendance = 25000
} else {
attendance = 20000
}
}
}
Run Code Online (Sandbox Code Playgroud)
...
fun chooseTeam() {
val homeTeam = Team(name = "Everton")
println("the home team is $homeTeam.aggressive so they are ${if ($homeTeam == "aggressive") "angry" else "timid" }")
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试根据if是否$homeTeam.aggressive为true 来分配lambda字符串的值.
但是我在lambda上得到了红线,所以很明显语法似乎没有了.有人能告诉我代码有什么问题吗?
将变量分配给函数调用实际上是调用该函数还是只是存储它(以便它准备好被调用)?
例如:
val userData = GraphRequest.newMeRequest(
accessToken,
object : GraphRequest.GraphJSONObjectCallback {
override fun onCompleted(`object`: JSONObject?, response: GraphResponse?) {
Log.d(TAG, `object`.toString())
}
}
)
Run Code Online (Sandbox Code Playgroud)
实际上打电话GraphRequest.newMeRequest()?
我想为我的云功能添加安全性,因此我删除了allUsers调用它的访问权限 - 所以我只能从我的 GCP 内的服务帐户调用它。
所以我完全按照 GCP 文档中的教程进行操作:
云功能
async function createTask(taskName, functionToFire, payload, fireAt){
const tasksClient = new CloudTasksClient()
const projectId = JSON.parse(process.env.FIREBASE_CONFIG).projectId
console.log(`${taskName} will fire ${functionToFire} at ${fireAt}...`)
const location = 'us-central1'
const queuePath = tasksClient.queuePath(projectId, location, taskName)
const url = `https://us-central1-${PROJECT_ID}.cloudfunctions.net/task/${functionToFire}`
const serviceAccountEmail = 'cloud-tasks@${PROJECT_ID}.iam.gserviceaccount.com';
// const sendAt = Date.now() / 1000 + 10 // plus 10 seconds of current epoch
const task = {
httpRequest: {
httpMethod: 'POST',
url,
oidcToken: {
serviceAccountEmail
}, …Run Code Online (Sandbox Code Playgroud) google-tasks-api google-cloud-platform google-cloud-functions google-iam
我有一个 SharedPreference: sharedPref.getBoolean("online", false)
如果我收到一条online错误通知,我想阻止它。如果用户离线,通常不会有通知,但我偶尔会收到通知,我希望将其作为备份以防止通知。
通知通过Firebase Cloud Messaging (FCM) 发送,以下是它在我的应用程序中的处理方式:
class CustomApplication : Application() {
val MATCH_CHANNEL_ID = "MATCH_CHANNEL"
companion object {
var database: AppDatabase? = null
}
override fun onCreate() {
super.onCreate()
val settings: FirebaseFirestoreSettings = FirebaseFirestoreSettings.Builder().setPersistenceEnabled(false).build()
FirebaseFirestore.getInstance().firestoreSettings = settings
CustomApplication.database = Room.databaseBuilder(this, AppDatabase::class.java, "AppDatabase").build()
createNotificationChannel()
}
private fun createNotificationChannel(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
val matchChannel = NotificationChannel(MATCH_CHANNEL_ID, "Nearby matches", NotificationManager.IMPORTANCE_HIGH)
matchChannel.description = "Nearby matches"
val manager: NotificationManager = getSystemService(NotificationManager::class.java)
manager.createNotificationChannel(matchChannel)
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果 …
kotlin ×5
java ×3
amazon-s3 ×1
android ×1
firebase ×1
google-iam ×1
javascript ×1
jquery ×1
jvm ×1